summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 19:09:07 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-10 19:09:07 +0000
commit8d439a694371cfdd95c0c03ff452c9096d3cc7f3 (patch)
tree14ef281438f753ded9d64d7475059fe95fb89a88
parent695225e97e2ea163dac3b63659c05eb36f94bfd9 (diff)
downloadchromium_src-8d439a694371cfdd95c0c03ff452c9096d3cc7f3.zip
chromium_src-8d439a694371cfdd95c0c03ff452c9096d3cc7f3.tar.gz
chromium_src-8d439a694371cfdd95c0c03ff452c9096d3cc7f3.tar.bz2
Make Chromium windows not hide auto-hide taskbars, take 2.
This is very similar to r10845, but also includes a regression fix for issue 8410, where locking and unlocking the screen would cause mispositioning of child content. BUG=20,8410 Review URL: http://codereview.chromium.org/42027 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11355 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/views/frame/browser_frame.cc60
-rw-r--r--chrome/browser/views/frame/browser_frame.h2
-rw-r--r--chrome/browser/views/frame/glass_browser_frame_view.cc19
-rw-r--r--chrome/browser/views/frame/glass_browser_frame_view.h2
-rw-r--r--chrome/browser/views/frame/opaque_browser_frame_view.cc17
-rw-r--r--chrome/common/win_util.cc12
-rw-r--r--chrome/common/win_util.h7
-rw-r--r--chrome/views/window.cc55
8 files changed, 125 insertions, 49 deletions
diff --git a/chrome/browser/views/frame/browser_frame.cc b/chrome/browser/views/frame/browser_frame.cc
index ef59a12..d830a81 100644
--- a/chrome/browser/views/frame/browser_frame.cc
+++ b/chrome/browser/views/frame/browser_frame.cc
@@ -119,22 +119,53 @@ LRESULT BrowserFrame::OnNCCalcSize(BOOL mode, LPARAM l_param) {
// We don't adjust the client area unless we're a tabbed browser window and
// are using the native frame.
if (!non_client_view_->UseNativeFrame() ||
- !browser_view_->IsBrowserTypeNormal() || !mode) {
+ !browser_view_->IsBrowserTypeNormal()) {
return Window::OnNCCalcSize(mode, l_param);
}
- // In fullscreen mode, we make the whole window client area.
- if (!browser_view_->IsFullscreen()) {
- NCCALCSIZE_PARAMS* params = reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param);
- int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
- params->rgrc[0].left += (border_thickness - kClientEdgeThickness);
- params->rgrc[0].right -= (border_thickness - kClientEdgeThickness);
- params->rgrc[0].bottom -= (border_thickness - kClientEdgeThickness);
+ RECT* client_rect = mode ?
+ &reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0] :
+ reinterpret_cast<RECT*>(l_param);
+ int border_thickness = 0;
+ if (browser_view_->IsMaximized()) {
+ // Make the maximized mode client rect fit the screen exactly, by
+ // subtracting the border Windows automatically adds for maximized mode.
+ border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
+ // Find all auto-hide taskbars along the screen edges and adjust in by the
+ // thickness of the auto-hide taskbar on each such edge, so the window isn't
+ // treated as a "fullscreen app", which would cause the taskbars to
+ // disappear.
+ HMONITOR monitor = MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTONEAREST);
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_LEFT, monitor))
+ client_rect->left += win_util::kAutoHideTaskbarThicknessPx;
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_RIGHT, monitor))
+ client_rect->right -= win_util::kAutoHideTaskbarThicknessPx;
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_BOTTOM, monitor)) {
+ client_rect->bottom -= win_util::kAutoHideTaskbarThicknessPx;
+ } else if (win_util::EdgeHasAutoHideTaskbar(ABE_TOP, monitor)) {
+ // Tricky bit. Due to a bug in DwmDefWindowProc()'s handling of
+ // WM_NCHITTEST, having any nonclient area atop the window causes the
+ // caption buttons to draw onscreen but not respond to mouse hover/clicks.
+ // So for a taskbar at the screen top, we can't push the client_rect->top
+ // down; instead, we move the bottom up by one pixel, which is the
+ // smallest change we can make and still get a client area less than the
+ // screen size. This is visibly ugly, but there seems to be no better
+ // solution.
+ --client_rect->bottom;
+ }
+ } else if (!browser_view_->IsFullscreen()) {
+ // We draw our own client edge over part of the default frame would be.
+ border_thickness = GetSystemMetrics(SM_CXSIZEFRAME) - kClientEdgeThickness;
}
+ client_rect->left += border_thickness;
+ client_rect->right -= border_thickness;
+ client_rect->bottom -= border_thickness;
UpdateDWMFrame();
- SetMsgHandled(TRUE);
+ // We'd like to return WVR_REDRAW in some cases here, but because we almost
+ // always have nonclient area (except in fullscreen mode, where it doesn't
+ // matter), we can't. See comments in window.cc:OnNCCalcSize() for more info.
return 0;
}
@@ -143,9 +174,8 @@ LRESULT BrowserFrame::OnNCHitTest(const CPoint& pt) {
if (non_client_view_->UseNativeFrame()) {
LRESULT result;
if (DwmDefWindowProc(GetHWND(), WM_NCHITTEST, 0, MAKELPARAM(pt.x, pt.y),
- &result)) {
+ &result))
return result;
- }
}
return Window::OnNCHitTest(pt);
}
@@ -182,12 +212,16 @@ void BrowserFrame::UpdateDWMFrame() {
// because the GDI-drawn text in the web content composited over it will
// become semi-transparent over any glass area.
MARGINS margins = { 0 };
- if (!browser_view_->IsFullscreen()) {
+ if (browser_view_->CanCurrentlyResize()) {
margins.cxLeftWidth = kClientEdgeThickness + 1;
margins.cxRightWidth = kClientEdgeThickness + 1;
+ margins.cyBottomHeight = kClientEdgeThickness + 1;
+ }
+ // In maximized mode, we only have a titlebar strip of glass, no side/bottom
+ // borders.
+ if (!browser_view_->IsFullscreen()) {
margins.cyTopHeight =
GetBoundsForTabStrip(browser_view_->tabstrip()).bottom();
- margins.cyBottomHeight = kClientEdgeThickness + 1;
}
DwmExtendFrameIntoClientArea(GetHWND(), &margins);
}
diff --git a/chrome/browser/views/frame/browser_frame.h b/chrome/browser/views/frame/browser_frame.h
index 3c95858..95ce96e 100644
--- a/chrome/browser/views/frame/browser_frame.h
+++ b/chrome/browser/views/frame/browser_frame.h
@@ -55,9 +55,9 @@ class BrowserFrame : public views::Window {
// Overridden from views::WidgetWin:
virtual bool AcceleratorPressed(views::Accelerator* accelerator);
virtual bool GetAccelerator(int cmd_id, views::Accelerator* accelerator);
- virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
virtual void OnEnterSizeMove();
virtual void OnEndSession(BOOL ending, UINT logoff);
+ virtual void OnInitMenuPopup(HMENU menu, UINT position, BOOL is_system_menu);
virtual LRESULT OnMouseActivate(HWND window,
UINT hittest_code,
UINT message);
diff --git a/chrome/browser/views/frame/glass_browser_frame_view.cc b/chrome/browser/views/frame/glass_browser_frame_view.cc
index 5812350..1798b6a 100644
--- a/chrome/browser/views/frame/glass_browser_frame_view.cc
+++ b/chrome/browser/views/frame/glass_browser_frame_view.cc
@@ -225,7 +225,8 @@ void GlassBrowserFrameView::Paint(ChromeCanvas* canvas) {
PaintDistributorLogo(canvas);
PaintToolbarBackground(canvas);
PaintOTRAvatar(canvas);
- PaintClientEdge(canvas);
+ if (!frame_->IsMaximized())
+ PaintRestoredClientEdge(canvas);
}
void GlassBrowserFrameView::Layout() {
@@ -238,16 +239,22 @@ void GlassBrowserFrameView::Layout() {
// GlassBrowserFrameView, private:
int GlassBrowserFrameView::FrameBorderThickness() const {
- return GetSystemMetrics(SM_CXSIZEFRAME);
+ return browser_view_->CanCurrentlyResize() ?
+ GetSystemMetrics(SM_CXSIZEFRAME) : 0;
}
int GlassBrowserFrameView::NonClientBorderThickness() const {
- return kNonClientBorderThickness;
+ return browser_view_->CanCurrentlyResize() ? kNonClientBorderThickness : 0;
}
int GlassBrowserFrameView::NonClientTopBorderHeight() const {
- return FrameBorderThickness() +
- (frame_->IsMaximized() ? 0 : kNonClientRestoredExtraThickness);
+ if (browser_view_->IsFullscreen())
+ return 0;
+ // We'd like to use FrameBorderThickness() here, but the maximized Aero glass
+ // frame has a 0 frame border around most edges and a CXSIZEFRAME-thick border
+ // at the top (see AeroGlassFrame::OnGetMinMaxInfo()).
+ return GetSystemMetrics(SM_CXSIZEFRAME) +
+ (browser_view_->IsMaximized() ? 0 : kNonClientRestoredExtraThickness);
}
void GlassBrowserFrameView::PaintDistributorLogo(ChromeCanvas* canvas) {
@@ -295,7 +302,7 @@ void GlassBrowserFrameView::PaintOTRAvatar(ChromeCanvas* canvas) {
otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false);
}
-void GlassBrowserFrameView::PaintClientEdge(ChromeCanvas* canvas) {
+void GlassBrowserFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) {
// The client edges start below the toolbar upper corner images regardless
// of how tall the toolbar itself is.
int client_area_top =
diff --git a/chrome/browser/views/frame/glass_browser_frame_view.h b/chrome/browser/views/frame/glass_browser_frame_view.h
index 166ebd8..bf25210 100644
--- a/chrome/browser/views/frame/glass_browser_frame_view.h
+++ b/chrome/browser/views/frame/glass_browser_frame_view.h
@@ -54,7 +54,7 @@ class GlassBrowserFrameView : public BrowserNonClientFrameView {
void PaintDistributorLogo(ChromeCanvas* canvas);
void PaintToolbarBackground(ChromeCanvas* canvas);
void PaintOTRAvatar(ChromeCanvas* canvas);
- void PaintClientEdge(ChromeCanvas* canvas);
+ void PaintRestoredClientEdge(ChromeCanvas* canvas);
// Layout various sub-components of this view.
void LayoutDistributorLogo();
diff --git a/chrome/browser/views/frame/opaque_browser_frame_view.cc b/chrome/browser/views/frame/opaque_browser_frame_view.cc
index 5d4df77..8452a37 100644
--- a/chrome/browser/views/frame/opaque_browser_frame_view.cc
+++ b/chrome/browser/views/frame/opaque_browser_frame_view.cc
@@ -505,7 +505,7 @@ void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size,
gfx::Path* window_mask) {
DCHECK(window_mask);
- if (browser_view_->IsFullscreen())
+ if (!browser_view_->CanCurrentlyResize())
return;
// Redefine the window visible region for the new size.
@@ -649,10 +649,7 @@ SkBitmap OpaqueBrowserFrameView::GetFavIconForTabIconView() {
// OpaqueBrowserFrameView, private:
int OpaqueBrowserFrameView::FrameBorderThickness() const {
- if (browser_view_->IsFullscreen())
- return 0;
- return frame_->IsMaximized() ?
- GetSystemMetrics(SM_CXSIZEFRAME) : kFrameBorderThickness;
+ return browser_view_->CanCurrentlyResize() ? kFrameBorderThickness : 0;
}
int OpaqueBrowserFrameView::TopResizeHeight() const {
@@ -920,13 +917,11 @@ void OpaqueBrowserFrameView::LayoutWindowControls() {
// button to the screen corner to obey Fitts' Law.
int right_extra_width = is_maximized ?
(kFrameBorderThickness - kFrameShadowThickness) : 0;
- int right_spacing = is_maximized ?
- (GetSystemMetrics(SM_CXSIZEFRAME) + right_extra_width) : frame_thickness;
gfx::Size close_button_size = close_button_->GetPreferredSize();
- close_button_->SetBounds(width() - close_button_size.width() - right_spacing,
- caption_y,
- close_button_size.width() + right_extra_width,
- close_button_size.height() + top_extra_height);
+ close_button_->SetBounds(width() - close_button_size.width() -
+ right_extra_width - frame_thickness, caption_y,
+ close_button_size.width() + right_extra_width,
+ close_button_size.height() + top_extra_height);
// When the window is restored, we show a maximized button; otherwise, we show
// a restore button.
diff --git a/chrome/common/win_util.cc b/chrome/common/win_util.cc
index 07a1b08..9569b00 100644
--- a/chrome/common/win_util.cc
+++ b/chrome/common/win_util.cc
@@ -28,6 +28,8 @@
namespace win_util {
+const int kAutoHideTaskbarThicknessPx = 2;
+
namespace {
// Enforce visible dialog box.
@@ -626,6 +628,16 @@ void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref,
}
}
+bool EdgeHasAutoHideTaskbar(UINT edge, HMONITOR monitor) {
+ APPBARDATA taskbar_data = { 0 };
+ taskbar_data.cbSize = sizeof APPBARDATA;
+ taskbar_data.uEdge = edge;
+ HWND taskbar = reinterpret_cast<HWND>(SHAppBarMessage(ABM_GETAUTOHIDEBAR,
+ &taskbar_data));
+ return ::IsWindow(taskbar) &&
+ (MonitorFromWindow(taskbar, MONITOR_DEFAULTTONEAREST) == monitor);
+}
+
HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only) {
HANDLE valid_section = NULL;
DWORD access = STANDARD_RIGHTS_REQUIRED | FILE_MAP_READ;
diff --git a/chrome/common/win_util.h b/chrome/common/win_util.h
index c93b098..8e703cb 100644
--- a/chrome/common/win_util.h
+++ b/chrome/common/win_util.h
@@ -211,6 +211,10 @@ void AdjustWindowToFit(HWND hwnd);
void CenterAndSizeWindow(HWND parent, HWND window, const SIZE& pref,
bool pref_is_client);
+// Returns true if edge |edge| (one of ABE_LEFT, TOP, RIGHT, or BOTTOM) of
+// monitor |monitor| has an auto-hiding taskbar.
+bool EdgeHasAutoHideTaskbar(UINT edge, HMONITOR monitor);
+
// Duplicates a section handle from another process to the current process.
// Returns the new valid handle if the function succeed. NULL otherwise.
HANDLE GetSectionFromProcess(HANDLE section, HANDLE process, bool read_only);
@@ -274,6 +278,9 @@ int MessageBox(HWND hwnd,
// Returns the system set window title font.
ChromeFont GetWindowTitleFont();
+// The thickness of an auto-hide taskbar in pixels.
+extern const int kAutoHideTaskbarThicknessPx;
+
} // namespace win_util
#endif // CHROME_COMMON_WIN_UTIL_H_
diff --git a/chrome/views/window.cc b/chrome/views/window.cc
index fb5ce76..d8ea0e9 100644
--- a/chrome/views/window.cc
+++ b/chrome/views/window.cc
@@ -569,8 +569,40 @@ LRESULT Window::OnNCCalcSize(BOOL mode, LPARAM l_param) {
if (non_client_view_->UseNativeFrame())
return WidgetWin::OnNCCalcSize(mode, l_param);
- // We need to repaint all when the window bounds change.
- return WVR_REDRAW;
+ RECT* client_rect = mode ?
+ &reinterpret_cast<NCCALCSIZE_PARAMS*>(l_param)->rgrc[0] :
+ reinterpret_cast<RECT*>(l_param);
+ if (IsMaximized()) {
+ // Make the maximized mode client rect fit the screen exactly, by
+ // subtracting the border Windows automatically adds for maximized mode.
+ int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME);
+ InflateRect(client_rect, -border_thickness, -border_thickness);
+
+ // Find all auto-hide taskbars along the screen edges and adjust in by the
+ // thickness of the auto-hide taskbar on each such edge, so the window isn't
+ // treated as a "fullscreen app", which would cause the taskbars to
+ // disappear.
+ HMONITOR monitor = MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTONEAREST);
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_LEFT, monitor))
+ client_rect->left += win_util::kAutoHideTaskbarThicknessPx;
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_TOP, monitor))
+ client_rect->top += win_util::kAutoHideTaskbarThicknessPx;
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_RIGHT, monitor))
+ client_rect->right -= win_util::kAutoHideTaskbarThicknessPx;
+ if (win_util::EdgeHasAutoHideTaskbar(ABE_BOTTOM, monitor))
+ client_rect->bottom -= win_util::kAutoHideTaskbarThicknessPx;
+
+ // We cannot return WVR_REDRAW when there is nonclient area, or Windows
+ // exhibits bugs where client pixels and child HWNDs are mispositioned by
+ // the width/height of the upper-left nonclient area.
+ return 0;
+ }
+
+ // If the window bounds change, we're going to relayout and repaint anyway.
+ // Returning WVR_REDRAW avoids an extra paint before that of the old client
+ // pixels in the (now wrong) location, and thus makes actions like resizing a
+ // window from the left edge look slightly less broken.
+ return mode ? WVR_REDRAW : 0;
}
LRESULT Window::OnNCHitTest(const CPoint& point) {
@@ -1099,21 +1131,10 @@ void Window::ResetWindowRegion(bool force) {
CRect window_rect;
GetWindowRect(&window_rect);
HRGN new_region;
- if (IsMaximized()) {
- HMONITOR monitor = MonitorFromWindow(GetHWND(), MONITOR_DEFAULTTONEAREST);
- MONITORINFO mi;
- mi.cbSize = sizeof mi;
- GetMonitorInfo(monitor, &mi);
- CRect work_rect = mi.rcWork;
- work_rect.OffsetRect(-window_rect.left, -window_rect.top);
- new_region = CreateRectRgnIndirect(&work_rect);
- } else {
- gfx::Path window_mask;
- non_client_view_->GetWindowMask(gfx::Size(window_rect.Width(),
- window_rect.Height()),
- &window_mask);
- new_region = window_mask.CreateHRGN();
- }
+ gfx::Path window_mask;
+ non_client_view_->GetWindowMask(
+ gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask);
+ new_region = window_mask.CreateHRGN();
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
// SetWindowRgn takes ownership of the HRGN created by CreateHRGN.