Skip to content

Commit

Permalink
Permission prompts show in the top-left corner in fullscreen mode.
Browse files Browse the repository at this point in the history
Previously they were shown in the center, which causes interference with
the fullscreen notification. This way, they are treated more
consistently both in and out of fullscreen mode.

BUG=623862,624296
TEST=On https://permission.site, click Fullscreen then Location. The location
  prompt should be in the top-left corner and not overlapping the "Press Esc to
  exit full screen" bubble.
TEST=As above, but with the browser window on a secondary monitor.
TEST=As above, but in Arabic or Hebrew language (should be in top-right corner).

Review-Url: https://codereview.chromium.org/2109663005
Cr-Commit-Position: refs/heads/master@{#403840}
  • Loading branch information
mgiuca authored and Commit bot committed Jul 6, 2016
1 parent 6476000 commit 22beefb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,9 @@ void PermissionsBubbleDialogDelegateView::UpdateAnchor(
new views::BubbleBorder(adjusted_arrow, shadow(), color())));

// Reposition the bubble based on the updated arrow and view.
if (anchor_view)
SetAnchorView(anchor_view);
else
SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
SetAnchorView(anchor_view);
// The anchor rect is ignored unless |anchor_view| is nullptr.
SetAnchorRect(gfx::Rect(anchor_point, gfx::Size()));
}

//////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ class PermissionBubbleViewViews : public PermissionBubbleView {
private:
// These three functions have separate implementations for Views-based and
// Cocoa-based browsers, to allow this bubble to be used in either.

// Returns the view to anchor the permission bubble to. May be null.
views::View* GetAnchorView();
// Returns the anchor point to anchor the permission bubble to, as a fallback.
// Only used if GetAnchorView() returns nullptr.
gfx::Point GetAnchorPoint();
// Returns the type of arrow to display on the permission bubble.
views::BubbleBorder::Arrow GetAnchorArrow();

Browser* browser_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,39 @@
#include "chrome/browser/ui/views/location_bar/location_icon_view.h"
#include "chrome/browser/ui/views/website_settings/permissions_bubble_view.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/vector2d.h"

// The Views browser implementation of PermissionBubbleViewViews'
// anchor methods. Views browsers have a native View to anchor the bubble to,
// which these functions provide.

// Left margin for the bubble when anchored to the top of the screen in
// fullscreen mode.
const int kFullscreenLeftMargin = 40;

views::View* PermissionBubbleViewViews::GetAnchorView() {
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);

if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
return browser_view->GetLocationBarView()->location_icon_view();

return browser_view->top_container();
// Fall back to GetAnchorPoint().
return nullptr;
}

gfx::Point PermissionBubbleViewViews::GetAnchorPoint() {
return gfx::Point();
BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_);
// Get position in view (taking RTL displays into account).
int x_within_browser_view =
browser_view->GetMirroredXInView(kFullscreenLeftMargin);
// Get position in screen (taking browser view origin into account, which may
// not be 0,0 if there are multiple displays).
gfx::Point browser_view_origin = browser_view->GetBoundsInScreen().origin();
return browser_view_origin + gfx::Vector2d(x_within_browser_view, 0);
}

views::BubbleBorder::Arrow PermissionBubbleViewViews::GetAnchorArrow() {
if (browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR))
return views::BubbleBorder::TOP_LEFT;
return views::BubbleBorder::NONE;
return views::BubbleBorder::TOP_LEFT;
}

// static
Expand Down

0 comments on commit 22beefb

Please sign in to comment.