Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Fixed Bookmarks navigation
Browse files Browse the repository at this point in the history
Also added support for bookmarks in all the windows as stated in the spec: #1331
  • Loading branch information
keianhzo authored and MortimerGoro committed Jul 10, 2019
1 parent 86bc0f9 commit 57cf4b2
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,9 @@
import org.mozilla.vrbrowser.search.SearchEngineWrapper;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.OffscreenDisplay;
import org.mozilla.vrbrowser.ui.views.BookmarksView;
import org.mozilla.vrbrowser.ui.widgets.BookmarkListener;
import org.mozilla.vrbrowser.ui.widgets.KeyboardWidget;
import org.mozilla.vrbrowser.ui.widgets.NavigationBarWidget;
import org.mozilla.vrbrowser.ui.widgets.RootWidget;
import org.mozilla.vrbrowser.ui.widgets.TopBarWidget;
import org.mozilla.vrbrowser.ui.widgets.TrayListener;
import org.mozilla.vrbrowser.ui.widgets.TrayWidget;
import org.mozilla.vrbrowser.ui.widgets.UIWidget;
import org.mozilla.vrbrowser.ui.widgets.VideoProjectionMenuWidget;
Expand All @@ -74,7 +70,6 @@

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -269,7 +264,6 @@ protected void initializeWidgets() {
});

// Add widget listeners
mWindows.getBookmarksView().addListeners(mNavigationBar, mTray);
mTray.addListeners(mWindows);

attachToWindow(mWindows.getFocusedWindow(), null);
Expand All @@ -281,6 +275,7 @@ private void attachToWindow(@NonNull WindowWidget aWindow, @Nullable WindowWidge
mPermissionDelegate.setParentWidgetHandle(aWindow.getHandle());
mNavigationBar.attachToWindow(aWindow);
mKeyboard.attachToWindow(aWindow);
mTray.attachToWindow(aWindow);

if (aPrevWindow != null) {
updateWidget(mNavigationBar);
Expand Down Expand Up @@ -364,6 +359,7 @@ protected void onDestroy() {
}

// Remove all widget listeners
mTray.removeListeners(mWindows);
mTray.onDestroy();
mWindows.onDestroy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.geckoview.WebRequestError;
import androidx.databinding.DataBindingUtil;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.BookmarksStore;
Expand All @@ -23,28 +20,18 @@
import org.mozilla.vrbrowser.databinding.BookmarksBinding;
import org.mozilla.vrbrowser.ui.adapters.BookmarkAdapter;
import org.mozilla.vrbrowser.ui.callbacks.BookmarkClickCallback;
import org.mozilla.vrbrowser.ui.widgets.BookmarkListener;
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.utils.UIThreadExecutor;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import mozilla.components.concept.storage.BookmarkNode;

public class BookmarksView extends FrameLayout implements BookmarksStore.BookmarkListener {

private BookmarksBinding mBinding;
private BookmarkAdapter mBookmarkAdapter;
private List<BookmarkListener> mBookmarkListeners;
private AudioEngine mAudio;
private boolean mIgnoreNextListener;
private WindowWidget mAttachedWindow;

public BookmarksView(Context aContext) {
super(aContext);
Expand All @@ -62,8 +49,6 @@ public BookmarksView(Context aContext, AttributeSet aAttrs, int aDefStyle) {
}

private void initialize(Context aContext) {
mBookmarkListeners = new ArrayList<>();

mAudio = AudioEngine.fromContext(aContext);

LayoutInflater inflater = LayoutInflater.from(aContext);
Expand All @@ -80,48 +65,10 @@ private void initialize(Context aContext) {
setVisibility(GONE);
}

public void addListeners(BookmarkListener... listeners) {
mBookmarkListeners.addAll(Arrays.asList(listeners));
}

public void removeListeners(BookmarkListener... listeners) {
mBookmarkListeners.removeAll(Arrays.asList(listeners));
}

public void detachFromWindow() {
if (mAttachedWindow != null) {
mAttachedWindow.unsetView(this);
notifyBookmarksHidden(mAttachedWindow);
mAttachedWindow = null;
}
}

public void attachToWindow(@NonNull WindowWidget aWindow) {
if (mAttachedWindow == aWindow) {
return;
}
mAttachedWindow = aWindow;
mAttachedWindow.setView(this);
notifyBookmarksShown(mAttachedWindow);
}

public WindowWidget getAttachedWindow() {
return mAttachedWindow;
}

public void onDestroy() {
mBookmarkListeners.clear();
SessionManager.get().getBookmarkStore().removeListener(this);
}

private void notifyBookmarksShown(WindowWidget aWindow) {
mBookmarkListeners.forEach(listener -> listener.onBookmarksShown(aWindow));
}

private void notifyBookmarksHidden(WindowWidget aWindow) {
mBookmarkListeners.forEach(listener -> listener.onBookmarksHidden(aWindow));
}

private final BookmarkClickCallback mBookmarkClickCallback = new BookmarkClickCallback() {
@Override
public void onClick(BookmarkNode bookmark) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ public void detachFromWindow() {
mSessionStore.removeContentListener(this);
mSessionStore = null;
}
if (mAttachedWindow != null)
mAttachedWindow.removeBookmarksListener(this);
mAttachedWindow = null;
}

Expand All @@ -375,6 +377,7 @@ public void attachToWindow(@NonNull WindowWidget aWindow) {

mWidgetPlacement.parentHandle = aWindow.getHandle();
mAttachedWindow = aWindow;
mAttachedWindow.addBookmarksListener(this);

mSessionStore = aWindow.getSessionStore();
if (mSessionStore != null) {
Expand Down Expand Up @@ -634,7 +637,7 @@ public void release() {

@Override
public void onLocationChange(GeckoSession session, String url) {
if (mURLBar != null) {
if (mURLBar != null && !mAttachedWindow.isBookmarksVisible()) {
Log.d(LOGTAG, "Got location change");
mURLBar.setURL(url);
mReloadButton.setEnabled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.audio.AudioEngine;
import org.mozilla.vrbrowser.browser.SessionChangeListener;
import org.mozilla.vrbrowser.browser.engine.SessionManager;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.ui.views.UIButton;
import org.mozilla.vrbrowser.ui.widgets.settings.SettingsWidget;
Expand Down Expand Up @@ -273,20 +272,30 @@ public void detachFromWindow() {
mSessionStore.removeSessionChangeListener(this);
mSessionStore = null;
}
if (mAttachedWindow != null)
mAttachedWindow.removeBookmarksListener(this);
}

@Override
public void attachToWindow(@NonNull WindowWidget aWindow) {
if (mAttachedWindow == aWindow) {
return;
}
detachFromWindow();

mAttachedWindow = aWindow;
mAttachedWindow.addBookmarksListener(this);

mSessionStore = aWindow.getSessionStore();
if (mSessionStore != null) {
mSessionStore.addSessionChangeListener(this);
handleSessionState();
}

if (mAttachedWindow.isBookmarksVisible())
onBookmarksShown(aWindow);
else
onBookmarksHidden(aWindow);
}

// SessionStore.SessionChangeListener
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.MotionEvent;
Expand All @@ -19,16 +18,19 @@
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.mozilla.geckoview.AllowOrDeny;
import org.mozilla.geckoview.GeckoDisplay;
import org.mozilla.geckoview.GeckoResult;
import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.SessionChangeListener;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.VideoAvailabilityListener;
import org.mozilla.vrbrowser.browser.engine.SessionManager;
import org.mozilla.vrbrowser.browser.engine.SessionStore;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.ui.views.BookmarksView;
import org.mozilla.vrbrowser.ui.widgets.dialogs.ContextMenuWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.AlertPromptWidget;
Expand All @@ -37,12 +39,13 @@
import org.mozilla.vrbrowser.ui.widgets.prompts.ConfirmPromptWidget;
import org.mozilla.vrbrowser.ui.widgets.prompts.TextPromptWidget;

import androidx.annotation.NonNull;
import java.util.ArrayList;

import static org.mozilla.vrbrowser.utils.ServoUtils.isInstanceOfServoSession;

public class WindowWidget extends UIWidget implements SessionChangeListener,
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate, VideoAvailabilityListener {
GeckoSession.ContentDelegate, GeckoSession.PromptDelegate,
GeckoSession.NavigationDelegate, VideoAvailabilityListener {

private static final String LOGTAG = "VRB";

Expand Down Expand Up @@ -72,6 +75,8 @@ public class WindowWidget extends UIWidget implements SessionChangeListener,
private Point mLastMouseClickPos;
private SessionStore mSessionStore;
private int mWindowId;
private BookmarksView mBookmarksView;
private ArrayList<BookmarkListener> mBookmarksListeners;
private Windows.WindowPlacement mWindowPlacement = Windows.WindowPlacement.FRONT;

public WindowWidget(Context aContext, int windowId, boolean privateMode) {
Expand All @@ -85,8 +90,12 @@ public WindowWidget(Context aContext, int windowId, boolean privateMode) {
mSessionStore.addPromptListener(this);
mSessionStore.addContentListener(this);
mSessionStore.addVideoAvailabilityListener(this);
mSessionStore.addNavigationListener(this);
mSessionStore.newSession();

mBookmarksView = new BookmarksView(aContext);
mBookmarksListeners = new ArrayList<>();

mHandle = ((WidgetManagerDelegate)aContext).newWidgetHandle();
mWidgetPlacement = new WidgetPlacement(aContext);
initializeWidgetPlacement(mWidgetPlacement);
Expand Down Expand Up @@ -147,17 +156,22 @@ public void hide(@HideFlags int aHideFlag) {

@Override
protected void onDismiss() {
if (mView != null) {
if (isBookmarksVisible()) {
switchBookmarks();

} else {
SessionStore activeStore = SessionManager.get().getSessionStore(mWindowId);
if (activeStore.canGoBack()) {
activeStore.goBack();
}

unsetView(mView);
}
}

public void setView(View view) {
public void onDestroy() {
mBookmarksView.onDestroy();
}

private void setView(View view) {
pauseCompositor();
mView = view;
removeView(view);
Expand All @@ -177,7 +191,7 @@ public void setView(View view) {
postInvalidate();
}

public void unsetView(View view) {
private void unsetView(View view) {
if (mView != null && mView == view) {
mView = null;
removeView(view);
Expand All @@ -199,6 +213,31 @@ public void unsetView(View view) {
}
}

public boolean isBookmarksVisible() {
return (mView != null);
}

public void addBookmarksListener(@NonNull BookmarkListener listener) {
mBookmarksListeners.add(listener);
}

public void removeBookmarksListener(@NonNull BookmarkListener listener) {
mBookmarksListeners.remove(listener);
}

public void switchBookmarks() {
if (mView == null) {
setView(mBookmarksView);
for (BookmarkListener listener : mBookmarksListeners)
listener.onBookmarksShown(this);

} else {
unsetView(mBookmarksView);
for (BookmarkListener listener : mBookmarksListeners)
listener.onBookmarksHidden(this);
}
}

public void pauseCompositor() {
if (mDisplay == null) {
return;
Expand Down Expand Up @@ -443,6 +482,7 @@ public void releaseWidget() {
mSessionStore.removePromptListener(this);
mSessionStore.removeContentListener(this);
mSessionStore.removeVideoAvailabilityListener(this);
mSessionStore.removeNavigationListener(this);
GeckoSession session = mSessionStore.getSession(mSessionId);
if (session == null) {
return;
Expand Down Expand Up @@ -724,4 +764,18 @@ public void onVideoAvailabilityChanged(boolean aVideosAvailable) {
WidgetManagerDelegate.CPU_LEVEL_NORMAL);
}

// GeckoSession.NavigationDelegate

@Override
public void onLocationChange(@NonNull GeckoSession session, @Nullable String url) {
if (isBookmarksVisible())
switchBookmarks();
}

@Nullable
@Override
public GeckoResult<AllowOrDeny> onLoadRequest(@NonNull GeckoSession session, @NonNull LoadRequest request) {
return GeckoResult.ALLOW;
}

}
Loading

0 comments on commit 57cf4b2

Please sign in to comment.