Commit 1da75893 authored by Wei Li's avatar Wei Li Committed by Commit Bot

Paint theme background correctly on Mac fullscreen

In fullscreen, the top menu bar may slide down on Mac. Chrome shift the
top UI under the menu bar. In such case, we should paint the theme
according to the new location. This CL fixes this by taking that Y
offset shift into account.

BUG=877438

Change-Id: I073fe3641b0d37af1d87b73fea79cebc8f71c94f
Reviewed-on: https://chromium-review.googlesource.com/1188834Reviewed-by: default avatarSidney San Martín <sdy@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Wei Li <weili@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586420}
parent 85afcbeb
......@@ -61,6 +61,10 @@ class BrowserNonClientFrameViewMac : public BrowserNonClientFrameView {
int GetAfterTabstripItemWidth() const;
CGFloat FullscreenBackingBarHeight() const;
// Calculate the y offset the top UI needs to shift down due to showing the
// slide down menu bar at the very top in full screen.
int TopUIFullscreenYOffset() const;
// Used to keep track of the update of kShowFullscreenToolbar preference.
PrefChangeRegistrar pref_registrar_;
......
......@@ -91,32 +91,21 @@ int BrowserNonClientFrameViewMac::GetTopInset(bool restored) const {
// Calculate the y offset for the tab strip because in fullscreen mode the tab
// strip may need to move under the slide down menu bar.
CGFloat y_offset = top_inset;
if (browser_view()->IsFullscreen()) {
CGFloat menu_bar_height =
[[[NSApplication sharedApplication] mainMenu] menuBarHeight];
CGFloat title_bar_height =
NSHeight([NSWindow frameRectForContentRect:NSZeroRect
styleMask:NSWindowStyleMaskTitled]);
CGFloat added_height =
[[fullscreen_toolbar_controller_ menubarTracker] menubarFraction] *
(menu_bar_height + title_bar_height);
y_offset += added_height;
if (added_height > 0) {
// When menubar shows up, we need to update mouse tracking area.
NSWindow* window = GetWidget()->GetNativeWindow();
NSRect content_bounds = [[window contentView] bounds];
// Backing bar tracking area uses native coordinates.
CGFloat backing_bar_height = FullscreenBackingBarHeight();
NSRect backing_bar_area =
NSMakeRect(0, NSMaxY(content_bounds) - backing_bar_height - y_offset,
NSWidth(content_bounds), backing_bar_height + y_offset);
[fullscreen_toolbar_controller_ updateToolbarFrame:backing_bar_area];
}
CGFloat y_offset = TopUIFullscreenYOffset();
if (y_offset > 0) {
// When menubar shows up, we need to update mouse tracking area.
NSWindow* window = GetWidget()->GetNativeWindow();
NSRect content_bounds = [[window contentView] bounds];
// Backing bar tracking area uses native coordinates.
CGFloat tracking_height =
FullscreenBackingBarHeight() + top_inset + y_offset;
NSRect backing_bar_area =
NSMakeRect(0, NSMaxY(content_bounds) - tracking_height,
NSWidth(content_bounds), tracking_height);
[fullscreen_toolbar_controller_ updateToolbarFrame:backing_bar_area];
}
return y_offset;
return y_offset + top_inset;
}
int BrowserNonClientFrameViewMac::GetAfterTabstripItemWidth() const {
......@@ -304,7 +293,8 @@ AvatarButtonStyle BrowserNonClientFrameViewMac::GetAvatarButtonStyle() const {
void BrowserNonClientFrameViewMac::PaintThemedFrame(gfx::Canvas* canvas) {
gfx::ImageSkia image = GetFrameImage();
canvas->TileImageInt(image, 0, 0, width(), image.height());
canvas->TileImageInt(image, 0, TopUIFullscreenYOffset(), width(),
image.height());
gfx::ImageSkia overlay = GetFrameOverlayImage();
canvas->DrawImageInt(overlay, 0, 0);
}
......@@ -329,3 +319,16 @@ CGFloat BrowserNonClientFrameViewMac::FullscreenBackingBarHeight() const {
return total_height;
}
int BrowserNonClientFrameViewMac::TopUIFullscreenYOffset() const {
if (!browser_view()->IsTabStripVisible() || !browser_view()->IsFullscreen())
return 0;
CGFloat menu_bar_height =
[[[NSApplication sharedApplication] mainMenu] menuBarHeight];
CGFloat title_bar_height =
NSHeight([NSWindow frameRectForContentRect:NSZeroRect
styleMask:NSWindowStyleMaskTitled]);
return [[fullscreen_toolbar_controller_ menubarTracker] menubarFraction] *
(menu_bar_height + title_bar_height);
}
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