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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 166 // window is visible. We use this position to place the incognito avatar | 166 // 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 | 167 // 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 | 168 // 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 | 169 // the correct position when the window becomes visible. This fixes bugs |
| 170 // where the icon appears to overlay the minimize button. Note that we | 170 // where the icon appears to overlay the minimize button. Note that we |
| 171 // will call Layout every time SetWindowPos is called with SWP_SHOWWINDOW, | 171 // will call Layout every time SetWindowPos is called with SWP_SHOWWINDOW, |
| 172 // however callers typically are careful about not specifying this flag | 172 // however callers typically are careful about not specifying this flag |
| 173 // unless necessary to avoid flicker. This may be invoked during creation | 173 // unless necessary to avoid flicker. This may be invoked during creation |
| 174 // on XP and before the non_client_view has been created. | 174 // on XP and before the non_client_view has been created. |
| 175 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param); | 175 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(l_param); |
| 176 if (window_pos->flags & SWP_SHOWWINDOW && | 176 auto* non_client_view = GetWidget()->non_client_view(); |
| 177 GetWidget()->non_client_view()) { | 177 if (window_pos->flags & SWP_SHOWWINDOW && non_client_view) { |
| 178 GetWidget()->non_client_view()->Layout(); | 178 non_client_view->Layout(); |
| 179 GetWidget()->non_client_view()->SchedulePaint(); | 179 non_client_view->SchedulePaint(); |
| 180 } | 180 } |
| 181 break; | 181 break; |
| 182 } | 182 } |
| 183 case WM_ERASEBKGND: { | 183 case WM_ERASEBKGND: { |
| 184 gfx::Insets insets; | 184 gfx::Insets insets; |
| 185 if (!did_gdi_clear_ && GetClientAreaInsets(&insets)) { | 185 if (!did_gdi_clear_ && GetClientAreaInsets(&insets)) { |
| 186 // This is necessary to avoid white flashing in the titlebar area around | 186 // This is necessary to avoid white flashing in the titlebar area around |
| 187 // the minimize/maximize/close buttons. | 187 // the minimize/maximize/close buttons. |
| 188 DCHECK_EQ(0, insets.top()); | 188 DCHECK_EQ(0, insets.top()); |
| 189 HDC dc = GetDC(hwnd); | 189 HDC dc = GetDC(hwnd); |
| 190 MARGINS margins = GetDWMFrameMargins(); | 190 MARGINS margins = GetDWMFrameMargins(); |
| 191 RECT client_rect; | 191 RECT client_rect; |
| 192 GetClientRect(hwnd, &client_rect); | 192 GetClientRect(hwnd, &client_rect); |
| 193 HBRUSH brush = CreateSolidBrush(0); | 193 HBRUSH brush = CreateSolidBrush(0); |
| 194 RECT rect = {0, 0, client_rect.right, margins.cyTopHeight}; | 194 RECT rect = {0, 0, client_rect.right, margins.cyTopHeight}; |
| 195 FillRect(dc, &rect, brush); | 195 FillRect(dc, &rect, brush); |
| 196 DeleteObject(brush); | 196 DeleteObject(brush); |
| 197 ReleaseDC(hwnd, dc); | 197 ReleaseDC(hwnd, dc); |
| 198 did_gdi_clear_ = true; | 198 did_gdi_clear_ = true; |
| 199 } | 199 } |
| 200 break; | 200 break; |
| 201 } | 201 } |
| 202 case WM_DWMCOLORIZATIONCOLORCHANGED: { | |
| 203 auto* non_client_view = GetWidget()->non_client_view(); | |
| 204 // Activation border may have changed color. | |
|
Peter Kasting
2016/10/06 08:02:47
Grammar Nazi Nit: Add "The" in front
| |
| 205 if (non_client_view) | |
| 206 non_client_view->SchedulePaint(); | |
| 207 break; | |
| 208 } | |
| 202 } | 209 } |
| 203 } | 210 } |
| 204 | 211 |
| 205 views::FrameMode BrowserDesktopWindowTreeHostWin::GetFrameMode() const { | 212 views::FrameMode BrowserDesktopWindowTreeHostWin::GetFrameMode() const { |
| 206 const views::FrameMode system_frame_mode = | 213 const views::FrameMode system_frame_mode = |
| 207 browser_frame_->CustomDrawSystemTitlebar() | 214 browser_frame_->CustomDrawSystemTitlebar() |
| 208 ? views::FrameMode::SYSTEM_DRAWN_NO_CONTROLS | 215 ? views::FrameMode::SYSTEM_DRAWN_NO_CONTROLS |
| 209 : views::FrameMode::SYSTEM_DRAWN; | 216 : views::FrameMode::SYSTEM_DRAWN; |
| 210 | 217 |
| 211 // We don't theme popup or app windows, so regardless of whether or not a | 218 // 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 | 250 |
| 244 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { | 251 void BrowserDesktopWindowTreeHostWin::FrameTypeChanged() { |
| 245 views::DesktopWindowTreeHostWin::FrameTypeChanged(); | 252 views::DesktopWindowTreeHostWin::FrameTypeChanged(); |
| 246 did_gdi_clear_ = false; | 253 did_gdi_clear_ = false; |
| 247 } | 254 } |
| 248 | 255 |
| 249 //////////////////////////////////////////////////////////////////////////////// | 256 //////////////////////////////////////////////////////////////////////////////// |
| 250 // BrowserDesktopWindowTreeHostWin, private: | 257 // BrowserDesktopWindowTreeHostWin, private: |
| 251 | 258 |
| 252 void BrowserDesktopWindowTreeHostWin::UpdateDWMFrame() { | 259 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 | 260 // 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. | 261 // 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 | 262 // because a theme is showing), so we explicitly check for that case rather |
| 270 // than checking browser_frame_->ShouldUseNativeFrame() here. Using that here | 263 // 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 | 264 // 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 | 265 // 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 | 266 // opaque frame. Instead, we use that function below to tell us whether the |
| 274 // frame is currently native or opaque. | 267 // frame is currently native or opaque. |
| 275 if (!GetWidget()->client_view() || !browser_view_->IsBrowserTypeNormal() || | 268 if (!GetWidget()->client_view() || !browser_view_->IsBrowserTypeNormal() || |
| 276 !DesktopWindowTreeHostWin::ShouldUseNativeFrame()) | 269 !DesktopWindowTreeHostWin::ShouldUseNativeFrame()) |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 292 return gfx::Insets(); | 285 return gfx::Insets(); |
| 293 | 286 |
| 294 const ui::ThemeProvider* const tp = GetWidget()->GetThemeProvider(); | 287 const ui::ThemeProvider* const tp = GetWidget()->GetThemeProvider(); |
| 295 return gfx::Insets( | 288 return gfx::Insets( |
| 296 0, tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE)->width(), | 289 0, tp->GetImageSkiaNamed(IDR_CONTENT_LEFT_SIDE)->width(), |
| 297 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER)->height(), | 290 tp->GetImageSkiaNamed(IDR_CONTENT_BOTTOM_CENTER)->height(), |
| 298 tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE)->width()); | 291 tp->GetImageSkiaNamed(IDR_CONTENT_RIGHT_SIDE)->width()); |
| 299 } | 292 } |
| 300 | 293 |
| 301 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { | 294 MARGINS BrowserDesktopWindowTreeHostWin::GetDWMFrameMargins() const { |
| 302 // If we're using the opaque frame or we're fullscreen we don't extend the | 295 // 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. | 296 // don't extend the glass in at all because it won't be visible. |
|
Peter Kasting
2016/10/06 08:02:47
Nit: Clearer (to me):
Don't extend the DWM frame
Bret
2016/10/06 20:48:10
Not quite accurate because DWM still draws non-cli
Peter Kasting
2016/10/11 20:01:38
What about:
Don't extend the DWM frame in unless
Bret
2016/10/11 20:48:19
Okay, I agree about not restating the code. Maybe
Peter Kasting
2016/10/11 20:56:51
I like your simple comment suggestion.
| |
| 304 if (!ShouldUseNativeFrame() || GetWidget()->IsFullscreen()) | 297 if (!ShouldUseNativeFrame() || GetWidget()->IsFullscreen() || |
| 298 browser_frame_->CustomDrawSystemTitlebar()) | |
| 305 return MARGINS{0}; | 299 return MARGINS{0}; |
| 306 | 300 |
| 307 // The glass should extend to the bottom of the tabstrip. | 301 // The glass should extend to the bottom of the tabstrip. |
| 308 HWND hwnd = GetHWND(); | 302 HWND hwnd = GetHWND(); |
| 309 gfx::Rect tabstrip_bounds( | 303 gfx::Rect tabstrip_bounds( |
| 310 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); | 304 browser_frame_->GetBoundsForTabStrip(browser_view_->tabstrip())); |
| 311 tabstrip_bounds = | 305 tabstrip_bounds = |
| 312 display::win::ScreenWin::DIPToClientRect(hwnd, tabstrip_bounds); | 306 display::win::ScreenWin::DIPToClientRect(hwnd, tabstrip_bounds); |
| 313 | 307 |
| 314 // Extend inwards far enough to go under the semitransparent client edges. | 308 // Extend inwards far enough to go under the semitransparent client edges. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 338 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( | 332 BrowserDesktopWindowTreeHost::CreateBrowserDesktopWindowTreeHost( |
| 339 views::internal::NativeWidgetDelegate* native_widget_delegate, | 333 views::internal::NativeWidgetDelegate* native_widget_delegate, |
| 340 views::DesktopNativeWidgetAura* desktop_native_widget_aura, | 334 views::DesktopNativeWidgetAura* desktop_native_widget_aura, |
| 341 BrowserView* browser_view, | 335 BrowserView* browser_view, |
| 342 BrowserFrame* browser_frame) { | 336 BrowserFrame* browser_frame) { |
| 343 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, | 337 return new BrowserDesktopWindowTreeHostWin(native_widget_delegate, |
| 344 desktop_native_widget_aura, | 338 desktop_native_widget_aura, |
| 345 browser_view, | 339 browser_view, |
| 346 browser_frame); | 340 browser_frame); |
| 347 } | 341 } |
| OLD | NEW |