Commit 86210735 authored by dbeam's avatar dbeam Committed by Commit bot

zoom bubble: Close if anchor is clicked while bubble is showing.

R=msw@chromium.org
BUG=366092

Review URL: https://codereview.chromium.org/420533002

Cr-Commit-Position: refs/heads/master@{#301043}
parent d6a92ee6
...@@ -49,17 +49,14 @@ void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) { ...@@ -49,17 +49,14 @@ void BubbleIconView::OnMouseReleased(const ui::MouseEvent& event) {
return; return;
} }
if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) { if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
OnExecuting(EXECUTE_SOURCE_MOUSE); ExecuteCommand(EXECUTE_SOURCE_MOUSE);
command_updater_->ExecuteCommand(command_id_);
}
} }
bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
if (event.key_code() == ui::VKEY_SPACE || if (event.key_code() == ui::VKEY_SPACE ||
event.key_code() == ui::VKEY_RETURN) { event.key_code() == ui::VKEY_RETURN) {
OnExecuting(EXECUTE_SOURCE_KEYBOARD); ExecuteCommand(EXECUTE_SOURCE_KEYBOARD);
command_updater_->ExecuteCommand(command_id_);
return true; return true;
} }
return false; return false;
...@@ -67,8 +64,13 @@ bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) { ...@@ -67,8 +64,13 @@ bool BubbleIconView::OnKeyPressed(const ui::KeyEvent& event) {
void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) { void BubbleIconView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) { if (event->type() == ui::ET_GESTURE_TAP) {
OnExecuting(EXECUTE_SOURCE_GESTURE); ExecuteCommand(EXECUTE_SOURCE_GESTURE);
command_updater_->ExecuteCommand(command_id_);
event->SetHandled(); event->SetHandled();
} }
} }
void BubbleIconView::ExecuteCommand(ExecuteSource source) {
OnExecuting(source);
if (command_updater_)
command_updater_->ExecuteCommand(command_id_);
}
...@@ -19,7 +19,7 @@ class BubbleIconView : public views::ImageView { ...@@ -19,7 +19,7 @@ class BubbleIconView : public views::ImageView {
}; };
explicit BubbleIconView(CommandUpdater* command_updater, int command_id); explicit BubbleIconView(CommandUpdater* command_updater, int command_id);
virtual ~BubbleIconView(); ~BubbleIconView() override;
// Returns true if a related bubble is showing. // Returns true if a related bubble is showing.
virtual bool IsBubbleShowing() const = 0; virtual bool IsBubbleShowing() const = 0;
...@@ -28,17 +28,20 @@ class BubbleIconView : public views::ImageView { ...@@ -28,17 +28,20 @@ class BubbleIconView : public views::ImageView {
virtual void OnExecuting(ExecuteSource execute_source) = 0; virtual void OnExecuting(ExecuteSource execute_source) = 0;
// views::ImageView: // views::ImageView:
virtual void GetAccessibleState(ui::AXViewState* state) override; void GetAccessibleState(ui::AXViewState* state) override;
virtual bool GetTooltipText(const gfx::Point& p, base::string16* tooltip) bool GetTooltipText(const gfx::Point& p, base::string16* tooltip) const
const override; override;
virtual bool OnMousePressed(const ui::MouseEvent& event) override; bool OnMousePressed(const ui::MouseEvent& event) override;
virtual void OnMouseReleased(const ui::MouseEvent& event) override; void OnMouseReleased(const ui::MouseEvent& event) override;
virtual bool OnKeyPressed(const ui::KeyEvent& event) override; bool OnKeyPressed(const ui::KeyEvent& event) override;
// ui::EventHandler: // ui::EventHandler:
virtual void OnGestureEvent(ui::GestureEvent* event) override; void OnGestureEvent(ui::GestureEvent* event) override;
private: private:
// Calls OnExecuting and runs |command_id_| with a valid |command_updater_|.
void ExecuteCommand(ExecuteSource source);
// The CommandUpdater for the Browser object that owns the location bar. // The CommandUpdater for the Browser object that owns the location bar.
CommandUpdater* command_updater_; CommandUpdater* command_updater_;
......
...@@ -112,8 +112,9 @@ void ZoomBubbleView::CloseBubble() { ...@@ -112,8 +112,9 @@ void ZoomBubbleView::CloseBubble() {
// static // static
bool ZoomBubbleView::IsShowing() { bool ZoomBubbleView::IsShowing() {
// The bubble may be in the process of closing. // The bubble is considered showing while closing.
return zoom_bubble_ != NULL && zoom_bubble_->GetWidget()->IsVisible(); return zoom_bubble_ != NULL && (zoom_bubble_->GetWidget()->IsVisible() ||
zoom_bubble_->GetWidget()->IsClosed());
} }
// static // static
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_BUBBLE_VIEW_H_
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/gtest_prod_util.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "chrome/browser/ui/views/frame/immersive_mode_controller.h" #include "chrome/browser/ui/views/frame/immersive_mode_controller.h"
#include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_observer.h"
...@@ -50,6 +51,8 @@ class ZoomBubbleView : public views::BubbleDelegateView, ...@@ -50,6 +51,8 @@ class ZoomBubbleView : public views::BubbleDelegateView,
static const ZoomBubbleView* GetZoomBubbleForTest(); static const ZoomBubbleView* GetZoomBubbleForTest();
private: private:
FRIEND_TEST_ALL_PREFIXES(ZoomBubbleBrowserTest, ImmersiveFullscreen);
// Stores information about the extension that initiated the zoom change, if // Stores information about the extension that initiated the zoom change, if
// any. // any.
struct ZoomBubbleExtensionInfo { struct ZoomBubbleExtensionInfo {
......
...@@ -96,7 +96,7 @@ IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, ImmersiveFullscreen) { ...@@ -96,7 +96,7 @@ IN_PROC_BROWSER_TEST_F(ZoomBubbleBrowserTest, ImmersiveFullscreen) {
immersive_controller->GetRevealedLock( immersive_controller->GetRevealedLock(
ImmersiveModeController::ANIMATE_REVEAL_NO)); ImmersiveModeController::ANIMATE_REVEAL_NO));
ASSERT_TRUE(immersive_controller->IsRevealed()); ASSERT_TRUE(immersive_controller->IsRevealed());
EXPECT_FALSE(ZoomBubbleView::IsShowing()); EXPECT_TRUE(ZoomBubbleView::zoom_bubble_->GetWidget()->IsClosed());
// The zoom bubble should be anchored when it is shown in immersive fullscreen // The zoom bubble should be anchored when it is shown in immersive fullscreen
// and the top-of-window views are revealed. // and the top-of-window views are revealed.
......
...@@ -16,8 +16,8 @@ ...@@ -16,8 +16,8 @@
#include "ui/gfx/size.h" #include "ui/gfx/size.h"
ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate)
: location_bar_delegate_(location_bar_delegate) { : BubbleIconView(nullptr, 0),
SetAccessibilityFocusable(true); location_bar_delegate_(location_bar_delegate) {
Update(NULL); Update(NULL);
} }
...@@ -39,44 +39,15 @@ void ZoomView::Update(ZoomController* zoom_controller) { ...@@ -39,44 +39,15 @@ void ZoomView::Update(ZoomController* zoom_controller) {
SetVisible(true); SetVisible(true);
} }
void ZoomView::GetAccessibleState(ui::AXViewState* state) { bool ZoomView::IsBubbleShowing() const {
state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); return ZoomBubbleView::IsShowing();
state->role = ui::AX_ROLE_BUTTON;
} }
bool ZoomView::GetTooltipText(const gfx::Point& p, void ZoomView::OnExecuting(BubbleIconView::ExecuteSource source) {
base::string16* tooltip) const { ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false);
// Don't show tooltip if the zoom bubble is displayed.
return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip);
}
bool ZoomView::OnMousePressed(const ui::MouseEvent& event) {
// Do nothing until mouse is released.
return true;
}
void ZoomView::OnMouseReleased(const ui::MouseEvent& event) {
if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location()))
ActivateBubble();
}
bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) {
if (event.key_code() != ui::VKEY_SPACE &&
event.key_code() != ui::VKEY_RETURN) {
return false;
}
ActivateBubble();
return true;
}
void ZoomView::OnGestureEvent(ui::GestureEvent* event) {
if (event->type() == ui::ET_GESTURE_TAP) {
ActivateBubble();
event->SetHandled();
}
} }
void ZoomView::ActivateBubble() { void ZoomView::GetAccessibleState(ui::AXViewState* state) {
ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); BubbleIconView::GetAccessibleState(state);
state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM);
} }
...@@ -5,44 +5,33 @@ ...@@ -5,44 +5,33 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_ZOOM_VIEW_H_
#include "base/basictypes.h" #include "base/macros.h"
#include "base/compiler_specific.h" #include "chrome/browser/ui/views/location_bar/bubble_icon_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "ui/views/controls/image_view.h"
class ZoomController; class ZoomController;
// View for the zoom icon in the Omnibox. // View for the zoom icon in the Omnibox.
class ZoomView : public views::ImageView { class ZoomView : public BubbleIconView {
public: public:
// Clicking on the ZoomView shows a ZoomBubbleView, which requires the current // Clicking on the ZoomView shows a ZoomBubbleView, which requires the current
// WebContents. Because the current WebContents changes as the user switches // WebContents. Because the current WebContents changes as the user switches
// tabs, it cannot be provided in the constructor. Instead, a // tabs, a LocationBarView::Delegate is supplied to queried for the current
// LocationBarView::Delegate is passed here so that it can be queried for the // WebContents when needed.
// current WebContents as needed.
explicit ZoomView(LocationBarView::Delegate* location_bar_delegate); explicit ZoomView(LocationBarView::Delegate* location_bar_delegate);
virtual ~ZoomView(); ~ZoomView() override;
// Updates the image and its tooltip appropriately, hiding or showing the icon // Updates the image and its tooltip appropriately, hiding or showing the icon
// as needed. // as needed.
void Update(ZoomController* zoom_controller); void Update(ZoomController* zoom_controller);
private: protected:
// views::ImageView: // BubbleIconView:
virtual void GetAccessibleState(ui::AXViewState* state) override; bool IsBubbleShowing() const override;
virtual bool GetTooltipText(const gfx::Point& p, void OnExecuting(BubbleIconView::ExecuteSource source) override;
base::string16* tooltip) const override; void GetAccessibleState(ui::AXViewState* state) override;
virtual bool OnMousePressed(const ui::MouseEvent& event) override;
virtual void OnMouseReleased(const ui::MouseEvent& event) override;
virtual bool OnKeyPressed(const ui::KeyEvent& event) override;
// ui::EventHandler:
virtual void OnGestureEvent(ui::GestureEvent* event) override;
// Helper method to show and focus the zoom bubble associated with this
// widget.
void ActivateBubble();
private:
// The delegate used to get the currently visible WebContents. // The delegate used to get the currently visible WebContents.
LocationBarView::Delegate* location_bar_delegate_; LocationBarView::Delegate* location_bar_delegate_;
......
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