Commit 64f3b43b authored by minch's avatar minch Committed by Commit Bot

back_gesture: Do not go back at the bottom page of browser.

Bug: 1002733
Change-Id: I6254d5d5feeb1e6fa1fcb72b8109453523683b97
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1867094Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Min Chen <minch@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707988}
parent 9b9864c5
......@@ -29,5 +29,9 @@ AccessibilityDelegate* ShellDelegateImpl::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate;
}
bool ShellDelegateImpl::CanGoBack(gfx::NativeWindow window) const {
return true;
}
} // namespace shell
} // namespace ash
......@@ -23,6 +23,7 @@ class ShellDelegateImpl : public ShellDelegate {
bool CanShowWindowForUser(const aura::Window* window) const override;
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
bool CanGoBack(gfx::NativeWindow window) const override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellDelegateImpl);
......
......@@ -11,6 +11,7 @@
#include "ash/ash_export.h"
#include "base/callback.h"
#include "base/strings/string16.h"
#include "ui/gfx/native_widget_types.h"
namespace aura {
class Window;
......@@ -37,6 +38,9 @@ class ASH_EXPORT ShellDelegate {
// Creates a accessibility delegate. Shell takes ownership of the delegate.
virtual AccessibilityDelegate* CreateAccessibilityDelegate() = 0;
// Check whether the current tab of the browser window can go back.
virtual bool CanGoBack(gfx::NativeWindow window) const = 0;
virtual void OpenKeyboardShortcutHelpPage() const {}
};
......
......@@ -29,4 +29,8 @@ AccessibilityDelegate* TestShellDelegate::CreateAccessibilityDelegate() {
return new DefaultAccessibilityDelegate;
}
bool TestShellDelegate::CanGoBack(gfx::NativeWindow window) const {
return true;
}
} // namespace ash
......@@ -21,6 +21,7 @@ class TestShellDelegate : public ShellDelegate {
bool CanShowWindowForUser(const aura::Window* window) const override;
std::unique_ptr<ScreenshotDelegate> CreateScreenshotDelegate() override;
AccessibilityDelegate* CreateAccessibilityDelegate() override;
bool CanGoBack(gfx::NativeWindow window) const override;
private:
DISALLOW_COPY_AND_ASSIGN(TestShellDelegate);
......
......@@ -9,6 +9,7 @@
#include "ash/public/cpp/ash_features.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/shell_delegate.h"
#include "ash/wm/back_gesture_affordance.h"
#include "ash/wm/overview/overview_controller.h"
#include "ash/wm/resize_shadow_controller.h"
......@@ -104,7 +105,7 @@ void OnDragCompleted(
}
// True if we can start swiping from left edge to go to previous page.
bool CanStartGoingBack() {
bool CanStartGoingBack(aura::Window* target) {
if (!features::IsSwipingFromLeftEdgeToGoBackEnabled())
return false;
......@@ -131,6 +132,18 @@ bool CanStartGoingBack() {
if (shell->home_screen_controller()->IsHomeScreenVisible())
return false;
views::Widget* widget = views::Widget::GetTopLevelWidgetForNativeView(target);
if (!widget)
return false;
aura::Window* native_window = widget->GetNativeWindow();
const int app_type = native_window->GetProperty(aura::client::kAppType);
// No need to show the back gesture affordance and go back if the active
// browser web contents can not go back.
if (app_type == static_cast<int>(AppType::BROWSER) ||
app_type == static_cast<int>(AppType::CHROME_APP)) {
return Shell::Get()->shell_delegate()->CanGoBack(widget->GetNativeWindow());
}
return true;
}
......@@ -879,12 +892,12 @@ void ToplevelWindowEventHandler::UpdateGestureTarget(
bool ToplevelWindowEventHandler::HandleGoingBackFromLeftEdge(
ui::GestureEvent* event) {
if (!CanStartGoingBack())
aura::Window* target = static_cast<aura::Window*>(event->target());
if (!CanStartGoingBack(target))
return false;
gfx::Point screen_location = event->location();
::wm::ConvertPointToScreen(static_cast<aura::Window*>(event->target()),
&screen_location);
::wm::ConvertPointToScreen(target, &screen_location);
switch (event->type()) {
case ui::ET_GESTURE_SCROLL_BEGIN: {
going_back_started_ = StartedAwayFromLeftArea(event);
......
......@@ -23,6 +23,7 @@
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "ui/aura/window.h"
#include "url/gurl.h"
......@@ -53,6 +54,18 @@ void ChromeShellDelegate::OpenKeyboardShortcutHelpPage() const {
Navigate(&params);
}
bool ChromeShellDelegate::CanGoBack(gfx::NativeWindow window) const {
BrowserView* browser_view =
BrowserView::GetBrowserViewForNativeWindow(window);
if (!browser_view)
return true;
content::WebContents* contents =
browser_view->browser()->tab_strip_model()->GetActiveWebContents();
if (!contents)
return false;
return contents->GetController().CanGoBack();
}
ash::AccessibilityDelegate* ChromeShellDelegate::CreateAccessibilityDelegate() {
return new ChromeAccessibilityDelegate;
}
......
......@@ -18,6 +18,7 @@ class ChromeShellDelegate : public ash::ShellDelegate {
std::unique_ptr<ash::ScreenshotDelegate> CreateScreenshotDelegate() override;
ash::AccessibilityDelegate* CreateAccessibilityDelegate() override;
void OpenKeyboardShortcutHelpPage() const override;
bool CanGoBack(gfx::NativeWindow window) const override;
private:
DISALLOW_COPY_AND_ASSIGN(ChromeShellDelegate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment