summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 04:08:57 +0000
committerdbeam@chromium.org <dbeam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-03 04:08:57 +0000
commit3c47f7247a0a92f61cb86661790ac2b386ee1030 (patch)
tree921d848474232748ee895c6bffabcbd07dec9b5d
parente9d8501b5d3ab85f383756a2ce17f8d4caea10c6 (diff)
downloadchromium_src-3c47f7247a0a92f61cb86661790ac2b386ee1030.zip
chromium_src-3c47f7247a0a92f61cb86661790ac2b386ee1030.tar.gz
chromium_src-3c47f7247a0a92f61cb86661790ac2b386ee1030.tar.bz2
[zoom bubble] make UI presentable in fullscreen mode on views
This patch also: - removes |anchor_widget|/|anchor| as a param from both GTK and views as it's now derived from |web_contents|. - moves notification observing to ZoomBubbleGtk from LocationBarGtk R=msw@chromium.org,pkasting@chromium.org BUG=167367 Review URL: https://chromiumcodereview.appspot.com/11674005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174934 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.cc22
-rw-r--r--chrome/browser/ui/gtk/location_bar_view_gtk.h7
-rw-r--r--chrome/browser/ui/gtk/zoom_bubble_gtk.cc37
-rw-r--r--chrome/browser/ui/gtk/zoom_bubble_gtk.h22
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.cc4
-rw-r--r--chrome/browser/ui/views/location_bar/location_bar_view.h3
-rw-r--r--chrome/browser/ui/views/location_bar/zoom_bubble_view.cc66
-rw-r--r--chrome/browser/ui/views/location_bar/zoom_bubble_view.h30
-rw-r--r--chrome/browser/ui/views/location_bar/zoom_view.cc3
9 files changed, 148 insertions, 46 deletions
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
index ac0abc3..caca211 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc
@@ -620,10 +620,6 @@ void LocationBarViewGtk::Init(bool popup_window_mode) {
registrar_.Add(this,
chrome::NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED,
content::Source<Profile>(browser()->profile()));
- registrar_.Add(this,
- chrome::NOTIFICATION_FULLSCREEN_CHANGED,
- content::Source<FullscreenController>(
- browser()->fullscreen_controller()));
edit_bookmarks_enabled_.Init(prefs::kEditBookmarksEnabled,
profile->GetPrefs(),
base::Bind(&LocationBarViewGtk::UpdateStarIcon,
@@ -1188,11 +1184,6 @@ void LocationBarViewGtk::Observe(int type,
break;
}
- case chrome::NOTIFICATION_FULLSCREEN_CHANGED: {
- ZoomBubbleGtk::CloseBubble();
- break;
- }
-
default:
NOTREACHED();
}
@@ -1532,7 +1523,7 @@ gboolean LocationBarViewGtk::OnZoomButtonPress(GtkWidget* widget,
if (event->button == 1 && GetWebContents()) {
// If the zoom icon is clicked, show the zoom bubble and keep it open until
// it loses focus.
- ZoomBubbleGtk::ShowBubble(GetZoomBubbleAnchor(), GetWebContents(), false);
+ ZoomBubbleGtk::ShowBubble(GetWebContents(), false);
return TRUE;
}
return FALSE;
@@ -1581,17 +1572,10 @@ gboolean LocationBarViewGtk::OnStarButtonPress(GtkWidget* widget,
}
void LocationBarViewGtk::ShowZoomBubble() {
- if (!zoom_.get() || toolbar_model_->GetInputInProgress())
+ if (toolbar_model_->GetInputInProgress() || !GetWebContents())
return;
- ZoomBubbleGtk::ShowBubble(GetZoomBubbleAnchor(), GetWebContents(), true);
-}
-
-GtkWidget* LocationBarViewGtk::GetZoomBubbleAnchor() {
- // |browser_->window()| is null until |browser_->CreateBrowserWindow()| has
- // been called.
- return browser_->window() && browser_->window()->IsFullscreen() ?
- GTK_WIDGET(browser()->window()->GetNativeWindow()) : zoom_.get();
+ ZoomBubbleGtk::ShowBubble(GetWebContents(), true);
}
void LocationBarViewGtk::ShowStarBubble(const GURL& url,
diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.h b/chrome/browser/ui/gtk/location_bar_view_gtk.h
index e734a1f..42bae90 100644
--- a/chrome/browser/ui/gtk/location_bar_view_gtk.h
+++ b/chrome/browser/ui/gtk/location_bar_view_gtk.h
@@ -106,6 +106,9 @@ class LocationBarViewGtk : public OmniboxEditController,
// true if it was a user action and a bubble could be shown.
void ZoomChangedForActiveTab(bool can_show_bubble);
+ // Returns the zoom widget. Used by the zoom bubble for an anchor.
+ GtkWidget* zoom_widget() { return zoom_.get(); }
+
// Set the starred state of the bookmark star.
void SetStarred(bool starred);
@@ -392,10 +395,6 @@ class LocationBarViewGtk : public OmniboxEditController,
void ShowFirstRunBubbleInternal();
- // Get the correct zoom bubble anchor according to whether the browser window
- // is fullscreen or not.
- GtkWidget* GetZoomBubbleAnchor();
-
// Shows the zoom bubble.
void ShowZoomBubble();
diff --git a/chrome/browser/ui/gtk/zoom_bubble_gtk.cc b/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
index 9d82d80a..2635026 100644
--- a/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk.cc
@@ -8,9 +8,16 @@
#include "base/utf_string_conversions.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/gtk/gtk_theme_service.h"
+#include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
+#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/pref_names.h"
+#include "content/public/browser/notification_details.h"
+#include "content/public/browser/notification_source.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
@@ -34,9 +41,16 @@ const int kBubbleAnchorHeight = 25;
} // namespace
// static
-void ZoomBubbleGtk::ShowBubble(GtkWidget* anchor,
- content::WebContents* web_contents,
+void ZoomBubbleGtk::ShowBubble(content::WebContents* web_contents,
bool auto_close) {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
+ DCHECK(browser && browser->window() && browser->fullscreen_controller());
+
+ LocationBar* location_bar = browser->window()->GetLocationBar();
+ GtkWidget* anchor = browser->window()->IsFullscreen() ?
+ GTK_WIDGET(browser->window()->GetNativeWindow()) :
+ static_cast<LocationBarViewGtk*>(location_bar)->zoom_widget();
+
// If the bubble is already showing and its |auto_close_| value is equal to
// |auto_close|, the bubble can be reused and only the label text needs to
// be updated.
@@ -51,7 +65,10 @@ void ZoomBubbleGtk::ShowBubble(GtkWidget* anchor,
CloseBubble();
DCHECK(!g_bubble);
- g_bubble = new ZoomBubbleGtk(anchor, web_contents, auto_close);
+ g_bubble = new ZoomBubbleGtk(anchor,
+ web_contents,
+ auto_close,
+ browser->fullscreen_controller());
}
}
@@ -68,7 +85,8 @@ bool ZoomBubbleGtk::IsShowing() {
ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor,
content::WebContents* web_contents,
- bool auto_close)
+ bool auto_close,
+ FullscreenController* fullscreen_controller)
: auto_close_(auto_close),
mouse_inside_(false),
web_contents_(web_contents) {
@@ -143,6 +161,10 @@ ZoomBubbleGtk::ZoomBubbleGtk(GtkWidget* anchor,
G_CALLBACK(&OnMouseLeaveThunk), this);
}
+ registrar_.Add(this,
+ chrome::NOTIFICATION_FULLSCREEN_CHANGED,
+ content::Source<FullscreenController>(fullscreen_controller));
+
StartTimerIfNecessary();
}
@@ -212,3 +234,10 @@ gboolean ZoomBubbleGtk::OnMouseLeave(GtkWidget* widget,
StartTimerIfNecessary();
return FALSE;
}
+
+void ZoomBubbleGtk::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
+ CloseBubble();
+}
diff --git a/chrome/browser/ui/gtk/zoom_bubble_gtk.h b/chrome/browser/ui/gtk/zoom_bubble_gtk.h
index fe79917..4a6b470 100644
--- a/chrome/browser/ui/gtk/zoom_bubble_gtk.h
+++ b/chrome/browser/ui/gtk/zoom_bubble_gtk.h
@@ -10,21 +10,26 @@
#include "base/basictypes.h"
#include "base/timer.h"
#include "chrome/browser/ui/gtk/bubble/bubble_gtk.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "ui/base/gtk/gtk_signal.h"
typedef struct _GtkWidget GtkWidget;
+class FullscreenController;
+
namespace content {
+class NotificationDetails;
+class NotificationSource;
class WebContents;
}
-class ZoomBubbleGtk {
+class ZoomBubbleGtk : public content::NotificationObserver {
public:
// Shows the zoom bubble below |anchor_widget| with an arrow pointing at
// |anchor_widget|. If |anchor_widget| is a toplevel window, the bubble will
// fixed positioned in the top right of corner of the widget with no arrow.
- static void ShowBubble(GtkWidget* anchor,
- content::WebContents* web_contents,
+ static void ShowBubble(content::WebContents* web_contents,
bool auto_close);
// Whether the zoom bubble is currently showing.
@@ -36,10 +41,16 @@ class ZoomBubbleGtk {
private:
ZoomBubbleGtk(GtkWidget* anchor,
content::WebContents* web_contents,
- bool auto_close);
+ bool auto_close,
+ FullscreenController* fullscreen_controller);
virtual ~ZoomBubbleGtk();
+ // content::NotificationObserver:
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
// Convenience method to start |timer_| if |auto_close_| is true.
void StartTimerIfNecessary();
@@ -86,6 +97,9 @@ class ZoomBubbleGtk {
// The BubbleGtk object containing the zoom bubble's content.
BubbleGtk* bubble_;
+ // Used to register for fullscreen change notifications.
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtk);
};
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc
index bfde348..03d3ee3 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc
@@ -550,8 +550,8 @@ void LocationBarView::ZoomChangedForActiveTab(bool can_show_bubble) {
Layout();
SchedulePaint();
- if (can_show_bubble && zoom_view_->visible())
- ZoomBubbleView::ShowBubble(zoom_view_, delegate_->GetWebContents(), true);
+ if (can_show_bubble && zoom_view_->visible() && delegate_->GetWebContents())
+ ZoomBubbleView::ShowBubble(delegate_->GetWebContents(), true);
}
void LocationBarView::RefreshZoomView() {
diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.h b/chrome/browser/ui/views/location_bar/location_bar_view.h
index abccf47..a15bdb2 100644
--- a/chrome/browser/ui/views/location_bar/location_bar_view.h
+++ b/chrome/browser/ui/views/location_bar/location_bar_view.h
@@ -174,6 +174,9 @@ class LocationBarView : public LocationBar,
// See comment in browser_window.h for more info.
void ZoomChangedForActiveTab(bool can_show_bubble);
+ // The zoom icon view. It may not be visible.
+ ZoomView* zoom_view() { return zoom_view_; }
+
// Sets |preview_enabled| for the PageAction View associated with this
// |page_action|. If |preview_enabled| is true, the view will display the
// PageActions icon even though it has not been activated by the extension.
diff --git a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
index d28292b..2b4fb39 100644
--- a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
+++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc
@@ -4,8 +4,17 @@
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
+#include "base/i18n/rtl.h"
#include "chrome/browser/chrome_page_zoom.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "chrome/browser/ui/views/location_bar/location_bar_view.h"
+#include "chrome/browser/ui/views/location_bar/zoom_view.h"
#include "chrome/browser/ui/zoom/zoom_controller.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "content/public/browser/notification_source.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
@@ -20,15 +29,24 @@ namespace {
// close automatically.
const int kBubbleCloseDelay = 1500;
+// The bubble's padding from the screen edge, used in fullscreen.
+const int kFullscreenPaddingEnd = 20;
+
} // namespace
// static
ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL;
// static
-void ZoomBubbleView::ShowBubble(views::View* anchor_view,
- content::WebContents* web_contents,
+void ZoomBubbleView::ShowBubble(content::WebContents* web_contents,
bool auto_close) {
+ Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
+ DCHECK(browser && browser->window() && browser->fullscreen_controller());
+
+ BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser);
+ views::View* anchor_view = browser->window()->IsFullscreen() ? NULL :
+ browser_view->GetLocationBarView()->zoom_view();
+
// If the bubble is already showing in this window and its |auto_close_| value
// is equal to |auto_close|, the bubble can be reused and only the label text
// needs to be updated.
@@ -42,8 +60,16 @@ void ZoomBubbleView::ShowBubble(views::View* anchor_view,
// current bubble must be closed and a new one created.
CloseBubble();
- zoom_bubble_ = new ZoomBubbleView(anchor_view, web_contents, auto_close);
+ zoom_bubble_ = new ZoomBubbleView(anchor_view,
+ web_contents,
+ auto_close,
+ browser->fullscreen_controller());
views::BubbleDelegateView::CreateBubble(zoom_bubble_);
+
+ // Adjust for fullscreen after creation as it relies on the content size.
+ if (browser->window()->IsFullscreen())
+ zoom_bubble_->AdjustForFullscreen(browser_view->GetBoundsInScreen());
+
zoom_bubble_->Show();
}
}
@@ -61,8 +87,10 @@ bool ZoomBubbleView::IsShowing() {
ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
content::WebContents* web_contents,
- bool auto_close)
- : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT),
+ bool auto_close,
+ FullscreenController* fullscreen_controller)
+ : BubbleDelegateView(anchor_view, anchor_view ?
+ views::BubbleBorder::TOP_RIGHT : views::BubbleBorder::NONE),
label_(NULL),
web_contents_(web_contents),
auto_close_(auto_close) {
@@ -70,11 +98,30 @@ ZoomBubbleView::ZoomBubbleView(views::View* anchor_view,
set_anchor_insets(gfx::Insets(5, 0, 5, 0));
set_use_focusless(auto_close);
set_notify_enter_exit_on_child(true);
+
+ registrar_.Add(this,
+ chrome::NOTIFICATION_FULLSCREEN_CHANGED,
+ content::Source<FullscreenController>(fullscreen_controller));
}
ZoomBubbleView::~ZoomBubbleView() {
}
+void ZoomBubbleView::AdjustForFullscreen(const gfx::Rect& screen_bounds) {
+ DCHECK(!anchor_view());
+
+ // TODO(dbeam): should RTL logic be done in views::BubbleDelegateView?
+ const size_t bubble_half_width = width() / 2;
+ const int x_pos = base::i18n::IsRTL() ?
+ screen_bounds.x() + bubble_half_width + kFullscreenPaddingEnd :
+ screen_bounds.right() - bubble_half_width - kFullscreenPaddingEnd;
+ set_anchor_point(gfx::Point(x_pos, screen_bounds.y()));
+
+ // Used to update |views::BubbleDelegate::anchor_point_| in a semi-hacky way.
+ // TODO(dbeam): update only the bounds of this view or its border or frame.
+ SizeToContents();
+}
+
void ZoomBubbleView::Refresh() {
ZoomController* zoom_controller =
ZoomController::FromWebContents(web_contents_);
@@ -122,7 +169,7 @@ void ZoomBubbleView::OnGestureEvent(ui::GestureEvent* event) {
// If an auto-closing bubble was tapped, show a non-auto-closing bubble in
// its place.
- ShowBubble(zoom_bubble_->anchor_view(), zoom_bubble_->web_contents_, false);
+ ShowBubble(zoom_bubble_->web_contents_, false);
event->SetHandled();
}
@@ -152,6 +199,13 @@ void ZoomBubbleView::Init() {
StartTimerIfNecessary();
}
+void ZoomBubbleView::Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, chrome::NOTIFICATION_FULLSCREEN_CHANGED);
+ CloseBubble();
+}
+
void ZoomBubbleView::WindowClosing() {
// |zoom_bubble_| can be a new bubble by this point (as Close(); doesn't
// call this right away). Only set to NULL when it's this bubble.
diff --git a/chrome/browser/ui/views/location_bar/zoom_bubble_view.h b/chrome/browser/ui/views/location_bar/zoom_bubble_view.h
index 34287ad..d905eb3 100644
--- a/chrome/browser/ui/views/location_bar/zoom_bubble_view.h
+++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.h
@@ -7,23 +7,29 @@
#include "base/basictypes.h"
#include "base/timer.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/label.h"
+class FullscreenController;
+
namespace content {
+class NotificationDetails;
+class NotificationSource;
class WebContents;
}
// View used to display the zoom percentage when it has changed.
class ZoomBubbleView : public views::BubbleDelegateView,
- public views::ButtonListener {
+ public views::ButtonListener,
+ public content::NotificationObserver {
public:
// Shows the bubble and automatically closes it after a short time period if
// |auto_close| is true.
- static void ShowBubble(views::View* anchor_view,
- content::WebContents* web_contents,
+ static void ShowBubble(content::WebContents* web_contents,
bool auto_close);
// Closes the showing bubble (if one exists).
@@ -35,9 +41,15 @@ class ZoomBubbleView : public views::BubbleDelegateView,
private:
ZoomBubbleView(views::View* anchor_view,
content::WebContents* web_contents,
- bool auto_close);
+ bool auto_close,
+ FullscreenController* fullscreen_controller);
virtual ~ZoomBubbleView();
+ // Place the bubble in the top right (left in RTL) of the |screen_bounds| that
+ // contain |web_contents_|'s browser window. Because the positioning is based
+ // on the size of the bubble, this must be called after the bubble is created.
+ void AdjustForFullscreen(const gfx::Rect& screen_bounds);
+
// Refreshes the bubble by changing the zoom percentage appropriately and
// resetting the timer if necessary.
void Refresh();
@@ -50,7 +62,7 @@ class ZoomBubbleView : public views::BubbleDelegateView,
// Stops the auto-close timer.
void StopTimer();
- // views::View method.
+ // views::View methods.
virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
@@ -65,6 +77,11 @@ class ZoomBubbleView : public views::BubbleDelegateView,
virtual void Init() OVERRIDE;
virtual void WindowClosing() OVERRIDE;
+ // content::NotificationObserver method.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
// Singleton instance of the zoom bubble. The zoom bubble can only be shown on
// the active browser window, so there is no case in which it will be shown
// twice at the same time.
@@ -82,6 +99,9 @@ class ZoomBubbleView : public views::BubbleDelegateView,
// Whether the currently displayed bubble will automatically close.
bool auto_close_;
+ // Used to register for fullscreen change notifications.
+ content::NotificationRegistrar registrar_;
+
DISALLOW_COPY_AND_ASSIGN(ZoomBubbleView);
};
diff --git a/chrome/browser/ui/views/location_bar/zoom_view.cc b/chrome/browser/ui/views/location_bar/zoom_view.cc
index 78be1e5..2a1c39d 100644
--- a/chrome/browser/ui/views/location_bar/zoom_view.cc
+++ b/chrome/browser/ui/views/location_bar/zoom_view.cc
@@ -85,6 +85,5 @@ int ZoomView::GetBuiltInHorizontalPadding() const {
}
void ZoomView::ActivateBubble() {
- ZoomBubbleView::ShowBubble(
- this, location_bar_delegate_->GetWebContents(), false);
+ ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false);
}