Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: chrome/browser/views/info_bubble.cc

Issue 376014: Reland Extension Installed InfoBubble (Closed)
Patch Set: Created 11 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/info_bubble.h ('k') | chrome/browser/views/location_bar_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/info_bubble.cc
diff --git a/chrome/browser/views/info_bubble.cc b/chrome/browser/views/info_bubble.cc
index 1218f46a063f717c43e856921117841eec867f66..4f39ba951c81ef6cbddfdedb84b55a9b650d0e9f 100644
--- a/chrome/browser/views/info_bubble.cc
+++ b/chrome/browser/views/info_bubble.cc
@@ -35,17 +35,16 @@ class BorderContents : public views::View {
// Given the size of the contents and the rect to point at, initializes the
// bubble and returns the bounds of both the border
// and the contents inside the bubble.
- // |is_rtl| is true if the UI is RTL and thus the arrow should default to the
- // right side of the bubble; otherwise it defaults to the left top corner, and
- // then is moved as necessary to try and fit the whole bubble on the same
- // monitor as the rect being pointed to.
+ // |prefer_arrow_on_right| specifies the preferred location for the arrow
+ // anchor. If the bubble does not fit on the monitor, the arrow location may
+ // changed so it can.
//
// TODO(pkasting): Maybe this should use mirroring transformations instead,
// which would hopefully simplify this code.
void InitAndGetBounds(
const gfx::Rect& position_relative_to, // In screen coordinates
const gfx::Size& contents_size,
- bool is_rtl,
+ bool prefer_arrow_on_right,
gfx::Rect* contents_bounds, // Returned in window coordinates
gfx::Rect* window_bounds); // Returned in screen coordinates
@@ -61,7 +60,7 @@ class BorderContents : public views::View {
void BorderContents::InitAndGetBounds(
const gfx::Rect& position_relative_to,
const gfx::Size& contents_size,
- bool is_rtl,
+ bool prefer_arrow_on_right,
gfx::Rect* contents_bounds,
gfx::Rect* window_bounds) {
// Margins between the contents and the inside of the border, in pixels.
@@ -80,8 +79,9 @@ void BorderContents::InitAndGetBounds(
local_contents_size.Enlarge(kLeftMargin + kRightMargin,
kTopMargin + kBottomMargin);
- // Try putting the arrow in its default location, and calculating the bounds.
- BubbleBorder::ArrowLocation arrow_location(is_rtl ?
+ // Try putting the arrow in its initial location, and calculating the
+ // bounds.
+ BubbleBorder::ArrowLocation arrow_location(prefer_arrow_on_right ?
BubbleBorder::TOP_RIGHT : BubbleBorder::TOP_LEFT);
bubble_border->set_arrow_location(arrow_location);
*window_bounds =
@@ -94,9 +94,9 @@ void BorderContents::InitAndGetBounds(
monitor_provider->GetMonitorWorkAreaMatching(position_relative_to));
if (!monitor_bounds.IsEmpty() && !monitor_bounds.Contains(*window_bounds)) {
// The bounds don't fit. Move the arrow to try and improve things.
- bool arrow_on_left =
- (is_rtl ? (window_bounds->x() < monitor_bounds.x()) :
- (window_bounds->right() <= monitor_bounds.right()));
+ bool arrow_on_left = prefer_arrow_on_right ?
+ (window_bounds->x() < monitor_bounds.x()) :
+ (window_bounds->right() <= monitor_bounds.right());
if (window_bounds->bottom() > monitor_bounds.bottom()) {
arrow_location = arrow_on_left ?
BubbleBorder::BOTTOM_LEFT : BubbleBorder::BOTTOM_RIGHT;
@@ -155,13 +155,14 @@ gfx::Rect BorderWidget::InitAndGetBounds(
HWND owner,
const gfx::Rect& position_relative_to,
const gfx::Size& contents_size,
- bool is_rtl) {
+ bool prefer_arrow_on_right) {
// Set up the border view and ask it to calculate our bounds (and our
// contents').
BorderContents* border_contents = new BorderContents;
gfx::Rect contents_bounds, window_bounds;
- border_contents->InitAndGetBounds(position_relative_to, contents_size, is_rtl,
- &contents_bounds, &window_bounds);
+ border_contents->InitAndGetBounds(position_relative_to, contents_size,
+ prefer_arrow_on_right, &contents_bounds,
+ &window_bounds);
// Initialize ourselves.
WidgetWin::Init(GetAncestor(owner, GA_ROOT), window_bounds);
@@ -247,12 +248,16 @@ void InfoBubble::Init(views::Window* parent,
// Calculate and set the bounds for all windows and views.
gfx::Rect window_bounds;
+
+ bool prefer_arrow_on_right =
+ (contents->UILayoutIsRightToLeft() == delegate->PreferOriginSideAnchor());
+
#if defined(OS_WIN)
border_.reset(new BorderWidget);
// Initialize and position the border window.
window_bounds = border_->InitAndGetBounds(GetNativeView(),
position_relative_to, contents->GetPreferredSize(),
- contents->UILayoutIsRightToLeft());
+ prefer_arrow_on_right);
// Make |contents| take up the entire contents view.
contents_view->SetLayoutManager(new views::FillLayout);
@@ -265,7 +270,7 @@ void InfoBubble::Init(views::Window* parent,
BorderContents* border_contents = new BorderContents;
gfx::Rect contents_bounds;
border_contents->InitAndGetBounds(position_relative_to,
- contents->GetPreferredSize(), contents->UILayoutIsRightToLeft(),
+ contents->GetPreferredSize(), prefer_arrow_on_right,
&contents_bounds, &window_bounds);
// This new view must be added before |contents| so it will paint under it.
contents_view->AddChildView(0, border_contents);
« no previous file with comments | « chrome/browser/views/info_bubble.h ('k') | chrome/browser/views/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698