Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h" | 5 #include "chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 return false; | 94 return false; |
| 95 | 95 |
| 96 if (GetWidget()->IsFullscreen()) { | 96 if (GetWidget()->IsFullscreen()) { |
| 97 // In fullscreen mode there is no frame. | 97 // In fullscreen mode there is no frame. |
| 98 *insets = gfx::Insets(); | 98 *insets = gfx::Insets(); |
| 99 } else { | 99 } else { |
| 100 const int frame_thickness = | 100 const int frame_thickness = |
| 101 display::win::ScreenWin::GetSystemMetricsForHwnd( | 101 display::win::ScreenWin::GetSystemMetricsForHwnd( |
| 102 GetHWND(), SM_CXSIZEFRAME); | 102 GetHWND(), SM_CXSIZEFRAME); |
| 103 // Reduce the Windows non-client border size because we extend the border | 103 // Reduce the Windows non-client border size because we extend the border |
| 104 // into our client area in UpdateDWMFrame(). | 104 // into our client area in UpdateDWMFrame(). The top inset must be 0 or |
| 105 // else Windows will draw a full native titlebar outside the client area. | |
| 105 *insets = gfx::Insets(0, frame_thickness, frame_thickness, | 106 *insets = gfx::Insets(0, frame_thickness, frame_thickness, |
| 106 frame_thickness) - GetClientEdgeThicknesses(); | 107 frame_thickness) - GetClientEdgeThicknesses(); |
| 107 } | 108 } |
| 108 return true; | 109 return true; |
| 109 } | 110 } |
| 110 | 111 |
| 111 void BrowserDesktopWindowTreeHostWin::HandleCreate() { | 112 void BrowserDesktopWindowTreeHostWin::HandleCreate() { |
| 112 DesktopWindowTreeHostWin::HandleCreate(); | 113 DesktopWindowTreeHostWin::HandleCreate(); |
| 113 browser_window_property_manager_ = | 114 browser_window_property_manager_ = |
| 114 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager( | 115 BrowserWindowPropertyManager::CreateBrowserWindowPropertyManager( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // window is visible. We use this position to place the incognito avatar | 167 // window is visible. We use this position to place the incognito avatar |
| 167 // in RTL mode, so when the window is shown, we need to re-layout and | 168 // in RTL mode, so when the window is shown, we need to re-layout and |
| 168 // schedule a paint for the non-client frame view so that the icon top has | 169 // schedule a paint for the non-client frame view so that the icon top has |
| 169 // the correct position when the window becomes visible. This fixes bugs | 170 // the correct position when the window becomes visible. This fixes bugs |
| 170 // where the icon appears to overlay the minimize button. Note that we | 171 // where the icon appears to overlay the minimize button. Note that we |
| 171 // will call Layout every time SetWindowPos is called with SWP_SHOWWINDOW, | 172 // will call Layout every time SetWindowPos is called with SWP_SHOWWINDOW, |
| 172 // however callers typically are careful about not specifying this flag | 173 // however callers typically are careful about not specifying this flag |
| 173 // unless necessary to avoid flicker. This may be invoked during creation | 174 // unless necessary to avoid flicker. This may be invoked during creation |
| 174 // on XP and before the non_client_view has been created. | 175 // on XP and before the non_client_view has been created. |
| 175 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param); | 176 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param); |
| 176 if (window_pos->flags & SWP_SHOWWINDOW && | 177 views::NonClientView* non_client_view = GetWidget()->non_client_view(); |
| 177 GetWidget()->non_client_view()) { | 178 if (window_pos->flags & SWP_SHOWWINDOW && non_client_view) { |
| 178 GetWidget()->non_client_view()->Layout(); | 179 non_client_view->Layout(); |
| 179 GetWidget()->non_client_view()->SchedulePaint(); | 180 non_client_view->SchedulePaint(); |
| 180 } | 181 } |
| 181 break; | 182 break; |
| 182 } | 183 } |
| 183 case WM_ERASEBKGND: { | 184 case WM_ERASEBKGND: { |
| 184 gfx::Insets insets; | 185 gfx::Insets insets; |
| 185 if (!did_gdi_clear_ && GetClientAreaInsets(&insets)) { | 186 if (!did_gdi_clear_ && GetClientAreaInsets(&insets)) { |
| 186 // This is necessary to avoid white flashing in the titlebar area around | 187 // This is necessary to avoid white flashing in the titlebar area around |
| 187 // the minimize/maximize/close buttons. | 188 // the minimize/maximize/close buttons. |
| 188 DCHECK_EQ(0, insets.top()); | 189 DCHECK_EQ(0, insets.top()); |
| 189 HDC dc = GetDC(hwnd); | 190 HDC dc = GetDC(hwnd); |
| 190 MARGINS margins = GetDWMFrameMargins(); | 191 MARGINS margins = GetDWMFrameMargins(); |
| 191 RECT client_rect; | 192 RECT client_rect; |
| 192 GetClientRect(hwnd, &client_rect); | 193 GetClientRect(hwnd, &client_rect); |
| 193 HBRUSH brush = CreateSolidBrush(0); | 194 HBRUSH brush = CreateSolidBrush(0); |
| 194 RECT rect = {0, 0, client_rect.right, margins.cyTopHeight}; | 195 RECT rect = {0, 0, client_rect.right, margins.cyTopHeight}; |
| 195 FillRect(dc, &rect, brush); | 196 FillRect(dc, &rect, brush); |
| 196 DeleteObject(brush); | 197 DeleteObject(brush); |
| 197 ReleaseDC(hwnd, dc); | 198 ReleaseDC(hwnd, dc); |
| 198 did_gdi_clear_ = true; | 199 did_gdi_clear_ = true; |
| 199 } | 200 } |
| 200 break; | 201 break; |
| 201 } | 202 } |
| 203 case WM_DWMCOLORIZATIONCOLORCHANGED: { | |
| 204 views::NonClientView* non_client_view = GetWidget()->non_client_view(); | |
| 205 // The activation border may have changed color. | |
|
Peter Kasting
2016/10/11 20:01:38
Tiny nit: I'd put this comment above the line abov
| |
| 206 if (non_client_view) | |
| 207 non_client_view->SchedulePaint(); | |
| 208 break; | |
| 209 } | |
| 202 } | 210 } |
| 203 } | 211 } |
| 204 | 212 |
| 205 views::FrameMode BrowserDesktopWindowTreeHostWin::GetFrameMode() const { | 213 views::FrameMode BrowserDesktopWindowTreeHostWin::GetFrameMode() const { |
| 206 const views::FrameMode system_frame_mode = | 214 const views::FrameMode system_frame_mode = |
| 207 browser_frame_->CustomDrawSystemTitlebar() | 215 browser_frame_->CustomDrawSystemTitlebar() |
| 208 ? views::FrameMode::SYSTEM_DRAWN_NO_CONTROLS | 216 ? views::FrameMode::SYSTEM_DRAWN_NO_CONTROLS |
| 209 : views::FrameMode::SYSTEM_DRAWN; | 217 : views::FrameMode::SYSTEM_DRAWN; |
| 210 | 218 |
| 211 // We don't theme popup or app windows, so regardless of whether or not a | 219 // We don't theme popup or app windows, so regardless of whether or not a |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 | 251 |
| 244 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { | 252 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { |
| 245 views::DesktopWindowTreeHostWin::FrameTypeChanged(); | 253 views::DesktopWindowTreeHostWin::FrameTypeChanged(); |
| 246 did_gdi_clear_ = false; | 254 did_gdi_clear_ = false; |
| 247 } | 255 } |
| 248 | 256 |
| 249 //////////////////////////////////////////////////////////////////////////////// | 257 //////////////////////////////////////////////////////////////////////////////// |
| 250 // BrowserDesktopWindowTreeHostWin, private: | 258 // BrowserDesktopWindowTreeHostWin, private: |
| 251 | 259 |
| 252 void BrowserDesktopWindowTreeHostWin::UpdateDWMFrame() { | 260 void BrowserDesktopWindowTreeHostWin::UpdateDWMFrame() { |
| 253 // With a custom titlebar we want the margins to always be 2 pixels, because | |
| 254 // that gives us the 1 pixel accent color border around the window (a 1 pixel | |
| 255 // margin is not sufficient, it will draw a messed-up-looking border instead). | |
| 256 // The other pixel ends up being 1-pixel-thick native titlebar (including | |
| 257 // caption buttons) but since we draw over that pixel in | |
| 258 // GlassBrowserFrameView::PaintTitlebar() it will be invisible and won't get | |
| 259 // mouse events. | |
| 260 if (browser_frame_->CustomDrawSystemTitlebar() && ShouldUseNativeFrame() && | |
| 261 !GetWidget()->IsFullscreen()) { | |
| 262 MARGINS margins = {2, 2, 2, 2}; | |
| 263 DwmExtendFrameIntoClientArea(GetHWND(), &margins); | |
| 264 return; | |
| 265 } | |
| 266 | |
| 267 // For "normal" windows on Aero, we always need to reset the glass area | 261 // For "normal" windows on Aero, we always need to reset the glass area |
| 268 // correctly, even if we're not currently showing the native frame (e.g. | 262 // correctly, even if we're not currently showing the native frame (e.g. |
| 269 // because a theme is showing), so we explicitly check for that case rather | 263 // because a theme is showing), so we explicitly check for that case rather |
| 270 // than checking browser_frame_->ShouldUseNativeFrame() here. Using that here | 264 // than checking browser_frame_->ShouldUseNativeFrame() here. Using that here |
| 271 // would mean we wouldn't reset the glass area to zero when moving from the | 265 // would mean we wouldn't reset the glass area to zero when moving from the |
| 272 // native frame to an opaque frame, leading to graphical glitches behind the | 266 // native frame to an opaque frame, leading to graphical glitches behind the |
| 273 // opaque frame. Instead, we use that function below to tell us whether the | 267 // opaque frame. Instead, we use that function below to tell us whether the |
| 274 // frame is currently native or opaque. | 268 // frame is currently native or opaque. |
| 275 if (!GetWidget()->client_view() || !browser_view_->IsBrowserTypeNormal() || | 269 if (!GetWidget()->client_view() || !browser_view_->IsBrowserTypeNormal() || |
| 276 !DesktopWindowTreeHostWin::ShouldUseNativeFrame()) | 270 !DesktopWindowTreeHostWin::ShouldUseNativeFrame()) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 292 return gfx::Insets(); | 286 return gfx::Insets(); |
| 293 | 287 |
| 294 const ui::ThemeProvider* const tp = GetWidget()->GetThemeProvider(); | 288 const ui::ThemeProvider* const tp = GetWidget()->GetThemeProvider(); |
| 295 return gfx::Insets( | 289 return gfx::Insets( |
| 296 0, tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE)->width(), | 290 0, tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE)->width(), |
| 297 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER)->height(), | 291 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER)->height(), |
| 298 tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE)->width()); | 292 tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE)->width()); |
| 299 } | 293 } |
| 300 | 294 |
| 301 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { | 295 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { |
| 302 // If we're using the opaque frame or we're fullscreen we don't extend the | 296 // If we're using the opaque frame or custom titlebar or we're fullscreen we |
| 303 // glass in at all because it won't be visible. | 297 // don't extend the glass in at all because it won't be visible. |
| 304 if (!ShouldUseNativeFrame() || GetWidget()->IsFullscreen()) | 298 if (!ShouldUseNativeFrame() || GetWidget()->IsFullscreen() || |
| 299 browser_frame_->CustomDrawSystemTitlebar()) | |
| 305 return MARGINS{0}; | 300 return MARGINS{0}; |
| 306 | 301 |
| 307 // The glass should extend to the bottom of the tabstrip. | 302 // The glass should extend to the bottom of the tabstrip. |
| 308 HWND hwnd = GetHWND(); | 303 HWND hwnd = GetHWND(); |
| 309 gfx::Rect tabstrip_bounds( | 304 gfx::Rect tabstrip_bounds( |
| 310 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); | 305 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); |
| 311 tabstrip_bounds = | 306 tabstrip_bounds = |
| 312 display::win::ScreenWin::DIPToClientRect(hwnd, tabstrip_bounds); | 307 display::win::ScreenWin::DIPToClientRect(hwnd, tabstrip_bounds); |
| 313 | 308 |
| 314 // Extend inwards far enough to go under the semitransparent client edges. | 309 // Extend inwards far enough to go under the semitransparent client edges. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 338 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( | 333 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( |
| 339 views::internal::NativeWidgetDelegate* native_widget_delegate, | 334 views::internal::NativeWidgetDelegate* native_widget_delegate, |
| 340 views::DesktopNativeWidgetAura* desktop_native_widget_aura, | 335 views::DesktopNativeWidgetAura* desktop_native_widget_aura, |
| 341 BrowserView* browser_view, | 336 BrowserView* browser_view, |
| 342 BrowserFrame* browser_frame) { | 337 BrowserFrame* browser_frame) { |
| 343 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, | 338 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, |
| 344 desktop_native_widget_aura, | 339 desktop_native_widget_aura, |
| 345 browser_view, | 340 browser_view, |
| 346 browser_frame); | 341 browser_frame); |
| 347 } | 342 } |
| OLD | NEW |