Skip to content

Commit

Permalink
Refactored GlassBrowserFrameView and BrowserDesktopTreeHostWin.
Browse files Browse the repository at this point in the history
Renamed many methods and constants. Updated their associated comments
to be consistent with how they're actually used and to hopefully be less
confusing to future readers. Also did some minor code cleanup.

No visible differences are intended as a result of this change.

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

Cr-Commit-Position: refs/heads/master@{#388542}
  • Loading branch information
bsep-chromium authored and Commit bot committed Apr 20, 2016
1 parent 8d2c683 commit 05e4802
Show file tree
Hide file tree
Showing 9 changed files with 193 additions and 201 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
#include "chrome/browser/themes/theme_service.h"
#include "chrome/browser/themes/theme_service_factory.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_frame_common_win.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/browser_window_property_manager_win.h"
#include "chrome/browser/ui/views/frame/system_menu_insertion_delegate_win.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/common/chrome_constants.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/theme_provider.h"
#include "ui/display/win/screen_win.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/controls/menu/native_menu_win.h"

namespace {

const int kClientEdgeThickness = 3;
// The amount of additional non-client area to draw beyond what we have Windows
// draw, in DIPs. Only used pre-Win 10.
const int kDWMFrameBorderExtensionDips = 3;

} // namespace

Expand Down Expand Up @@ -95,12 +98,15 @@ bool BrowserDesktopWindowTreeHostWin::GetClientAreaInsets(
}

int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
// In fullscreen mode, we have no frame. In restored mode, we draw our own
// client edge over part of the default frame.
if (GetWidget()->IsFullscreen())
if (GetWidget()->IsFullscreen()) {
// In fullscreen mode there is no frame.
border_thickness = 0;
else if (!IsMaximized() && base::win::GetVersion() < base::win::VERSION_WIN10)
border_thickness -= kClientEdgeThickness;
} else if (!IsMaximized() &&
base::win::GetVersion() < base::win::VERSION_WIN10) {
// Reduce the Windows non-client border size because we extended the border
// into our client area in UpdateDWMFrame().
border_thickness -= kDWMFrameBorderExtensionDips;
}
insets->Set(0, border_thickness, border_thickness, border_thickness);
return true;
}
Expand Down Expand Up @@ -226,8 +232,14 @@ bool BrowserDesktopWindowTreeHostWin::ShouldUseNativeFrame() const {
// context of the BrowserView destructor.
if (!browser_view_->browser())
return false;
return chrome::ShouldUseNativeFrame(browser_view_,
GetWidget()->GetThemeProvider());
// We don't theme popup or app windows, so regardless of whether or not a
// theme is active for normal browser windows, we don't want to use the custom
// frame for popups/apps.
if (!browser_view_->IsBrowserTypeNormal())
return true;
// Otherwise, we use the native frame when we're told we should by the theme
// provider (e.g. no custom theme is active).
return GetWidget()->GetThemeProvider()->ShouldUseNativeFrame();
}

void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() {
Expand Down Expand Up @@ -259,44 +271,42 @@ void BrowserDesktopWindowTreeHostWin::UpdateDWMFrame() {
MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const {
MARGINS margins = { 0 };

// If the opaque frame is visible, we use the default (zero) margins.
// Otherwise, we need to figure out how to extend the glass in.
if (GetWidget()->ShouldUseNativeFrame()) {
// In fullscreen mode, we don't extend glass into the client area at all,
// because the GDI-drawn text in the web content composited over it will
// become semi-transparent over any glass area.
if (!IsMaximized() && !GetWidget()->IsFullscreen()) {
margins.cyTopHeight = kClientEdgeThickness + 1;
// On Windows 10, we don't draw our own window border, so don't extend the
// nonclient area in for it. The top is extended so that the MARGINS isn't
// treated as an empty (ignored) extension.
if (base::win::GetVersion() >= base::win::VERSION_WIN10) {
margins.cxLeftWidth = 0;
margins.cxRightWidth = 0;
margins.cyBottomHeight = 0;
} else {
margins.cxLeftWidth = kClientEdgeThickness + 1;
margins.cxRightWidth = kClientEdgeThickness + 1;
margins.cyBottomHeight = kClientEdgeThickness + 1;
// If we're using the opaque frame or we're fullscreen we don't extend the
// glass in at all because it won't be visible.
if (!GetWidget()->ShouldUseNativeFrame() || GetWidget()->IsFullscreen())
return margins;

if (!IsMaximized()) {
if (base::win::GetVersion() < base::win::VERSION_WIN10) {
gfx::Point dip_margin(kDWMFrameBorderExtensionDips,
kDWMFrameBorderExtensionDips);
gfx::Point pixel_margin =
display::win::ScreenWin::DIPToScreenPoint(dip_margin);
margins.cxLeftWidth = pixel_margin.x();
margins.cxRightWidth = pixel_margin.x();
margins.cyBottomHeight = pixel_margin.y();

const bool md = ui::MaterialDesignController::IsModeMaterial();
if (!md) {
// Since the toolbar in non-md has rounded corners that show the glass
// frame behind, the extension of the glass area to the bottom of the
// tabstrip below isn't sufficient. We need to go down further to the
// bottom of the rounded corner region.
margins.cyTopHeight = pixel_margin.y();
}
}
// In maximized mode, we only have a titlebar strip of glass, no side/bottom
// borders.
if (!browser_view_->IsFullscreen()) {
gfx::Rect tabstrip_bounds(
browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip()));
tabstrip_bounds =
display::win::ScreenWin::DIPToClientRect(GetHWND(), tabstrip_bounds);
margins.cyTopHeight = tabstrip_bounds.bottom();

// On pre-Win 10, we need to offset the DWM frame into the toolbar so that
// the blackness doesn't show up on our rounded toolbar corners. In Win
// 10 and above there are no rounded corners, so this is unnecessary.
const int kDWMFrameTopOffset = 3;
if (base::win::GetVersion() < base::win::VERSION_WIN10)
margins.cyTopHeight += kDWMFrameTopOffset;
}
// Else, on Windows 10, we don't need extra border thickness because we draw
// right up to the edge of the client area and there are no rounded corners
// anywhere that we need to make sure are covered.
}

// Extend top for the tabstrip background.
gfx::Rect tabstrip_bounds(
browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip()));
tabstrip_bounds =
display::win::ScreenWin::DIPToClientRect(GetHWND(), tabstrip_bounds);
margins.cyTopHeight += tabstrip_bounds.bottom();

return margins;
}

Expand Down
25 changes: 0 additions & 25 deletions chrome/browser/ui/views/frame/browser_frame_common_win.cc

This file was deleted.

21 changes: 0 additions & 21 deletions chrome/browser/ui/views/frame/browser_frame_common_win.h

This file was deleted.

Loading

0 comments on commit 05e4802

Please sign in to comment.