| 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_frame_win.h" | 5 #include "chrome/browser/ui/views/frame/browser_frame_win.h" |
| 6 | 6 |
| 7 #include <dwmapi.h> | 7 #include <dwmapi.h> |
| 8 #include <shellapi.h> | 8 #include <shellapi.h> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 return true; | 188 return true; |
| 189 } | 189 } |
| 190 | 190 |
| 191 void BrowserFrameWin::UpdateFrameAfterFrameChange() { | 191 void BrowserFrameWin::UpdateFrameAfterFrameChange() { |
| 192 // We need to update the glass region on or off before the base class adjusts | 192 // We need to update the glass region on or off before the base class adjusts |
| 193 // the window region. | 193 // the window region. |
| 194 UpdateDWMFrame(); | 194 UpdateDWMFrame(); |
| 195 NativeWidgetWin::UpdateFrameAfterFrameChange(); | 195 NativeWidgetWin::UpdateFrameAfterFrameChange(); |
| 196 } | 196 } |
| 197 | 197 |
| 198 void BrowserFrameWin::OnEndSession(BOOL ending, UINT logoff) { | 198 void BrowserFrameWin::HandleEndSession() { |
| 199 browser::SessionEnding(); | 199 browser::SessionEnding(); |
| 200 } | 200 } |
| 201 | 201 |
| 202 void BrowserFrameWin::OnInitMenuPopup(HMENU menu, UINT position, | 202 void BrowserFrameWin::HandleInitMenuPopup() { |
| 203 BOOL is_system_menu) { | |
| 204 system_menu_->UpdateStates(); | 203 system_menu_->UpdateStates(); |
| 205 } | 204 } |
| 206 | 205 |
| 207 void BrowserFrameWin::OnWindowPosChanged(WINDOWPOS* window_pos) { | 206 void BrowserFrameWin::HandleVisibilityChanged(bool visible) { |
| 208 NativeWidgetWin::OnWindowPosChanged(window_pos); | |
| 209 UpdateDWMFrame(); | |
| 210 | |
| 211 // Windows lies to us about the position of the minimize button before a | 207 // Windows lies to us about the position of the minimize button before a |
| 212 // window is visible. We use this position to place the OTR avatar in RTL | 208 // window is visible. We use this position to place the OTR avatar in RTL |
| 213 // mode, so when the window is shown, we need to re-layout and schedule a | 209 // mode, so when the window is shown, we need to re-layout and schedule a |
| 214 // paint for the non-client frame view so that the icon top has the correct | 210 // paint for the non-client frame view so that the icon top has the correct |
| 215 // position when the window becomes visible. This fixes bugs where the icon | 211 // position when the window becomes visible. This fixes bugs where the icon |
| 216 // appears to overlay the minimize button. | 212 // appears to overlay the minimize button. |
| 217 // Note that we will call Layout every time SetWindowPos is called with | 213 // Note that we will call Layout every time SetWindowPos is called with |
| 218 // SWP_SHOWWINDOW, however callers typically are careful about not specifying | 214 // SWP_SHOWWINDOW, however callers typically are careful about not specifying |
| 219 // this flag unless necessary to avoid flicker. | 215 // this flag unless necessary to avoid flicker. |
| 220 // This may be invoked during creation on XP and before the non_client_view | 216 // This may be invoked during creation on XP and before the non_client_view |
| 221 // has been created. | 217 // has been created. |
| 222 if (window_pos->flags & SWP_SHOWWINDOW && GetWidget()->non_client_view()) { | 218 if (visible && GetWidget()->non_client_view()) { |
| 219 UpdateDWMFrame(); |
| 223 GetWidget()->non_client_view()->Layout(); | 220 GetWidget()->non_client_view()->Layout(); |
| 224 GetWidget()->non_client_view()->SchedulePaint(); | 221 GetWidget()->non_client_view()->SchedulePaint(); |
| 225 } | 222 } |
| 226 } | 223 } |
| 227 | 224 |
| 225 void BrowserFrameWin::HandleFrameChanged() { |
| 226 UpdateDWMFrame(); |
| 227 } |
| 228 |
| 228 void BrowserFrameWin::OnScreenReaderDetected() { | 229 void BrowserFrameWin::OnScreenReaderDetected() { |
| 229 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); | 230 BrowserAccessibilityState::GetInstance()->OnScreenReaderDetected(); |
| 230 NativeWidgetWin::OnScreenReaderDetected(); | 231 NativeWidgetWin::OnScreenReaderDetected(); |
| 231 } | 232 } |
| 232 | 233 |
| 233 bool BrowserFrameWin::ShouldUseNativeFrame() const { | 234 bool BrowserFrameWin::ShouldUseNativeFrame() const { |
| 234 // App panel windows draw their own frame. | 235 // App panel windows draw their own frame. |
| 235 if (browser_view_->IsPanel()) | 236 if (browser_view_->IsPanel()) |
| 236 return false; | 237 return false; |
| 237 | 238 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 262 void BrowserFrameWin::ShowWithWindowState(ui::WindowShowState show_state) { | 263 void BrowserFrameWin::ShowWithWindowState(ui::WindowShowState show_state) { |
| 263 AdjustFrameForImmersiveMode(); | 264 AdjustFrameForImmersiveMode(); |
| 264 views::NativeWidgetWin::ShowWithWindowState(show_state); | 265 views::NativeWidgetWin::ShowWithWindowState(show_state); |
| 265 } | 266 } |
| 266 | 267 |
| 267 void BrowserFrameWin::Close() { | 268 void BrowserFrameWin::Close() { |
| 268 CloseImmersiveFrame(); | 269 CloseImmersiveFrame(); |
| 269 views::NativeWidgetWin::Close(); | 270 views::NativeWidgetWin::Close(); |
| 270 } | 271 } |
| 271 | 272 |
| 272 void BrowserFrameWin::OnActivate(UINT action, BOOL minimized, HWND window) { | 273 void BrowserFrameWin::HandleActivationChanged(bool active) { |
| 273 if (action != WA_INACTIVE) | 274 if (active) |
| 274 CacheMinimizeButtonDelta(); | 275 CacheMinimizeButtonDelta(); |
| 275 views::NativeWidgetWin::OnActivate(action, minimized, window); | |
| 276 } | 276 } |
| 277 | 277 |
| 278 void BrowserFrameWin::FrameTypeChanged() { | 278 void BrowserFrameWin::FrameTypeChanged() { |
| 279 // In Windows 8 metro mode the frame type is set to FRAME_TYPE_FORCE_CUSTOM | 279 // In Windows 8 metro mode the frame type is set to FRAME_TYPE_FORCE_CUSTOM |
| 280 // by default. We reset it back to FRAME_TYPE_DEFAULT to ensure that we | 280 // by default. We reset it back to FRAME_TYPE_DEFAULT to ensure that we |
| 281 // don't end up defaulting to BrowserNonClientFrameView in all cases. | 281 // don't end up defaulting to BrowserNonClientFrameView in all cases. |
| 282 if (base::win::IsMetroProcess()) | 282 if (base::win::IsMetroProcess()) |
| 283 browser_frame_->set_frame_type(views::Widget::FRAME_TYPE_DEFAULT); | 283 browser_frame_->set_frame_type(views::Widget::FRAME_TYPE_DEFAULT); |
| 284 | 284 |
| 285 views::NativeWidgetWin::FrameTypeChanged(); | 285 views::NativeWidgetWin::FrameTypeChanged(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 if (minimize_button_offset > 0) | 339 if (minimize_button_offset > 0) |
| 340 return minimize_button_offset; | 340 return minimize_button_offset; |
| 341 | 341 |
| 342 // If we fail to get the minimize button offset via the WM_GETTITLEBARINFOEX | 342 // If we fail to get the minimize button offset via the WM_GETTITLEBARINFOEX |
| 343 // message then calculate and return this via the | 343 // message then calculate and return this via the |
| 344 // cached_minimize_button_x_delta_ member value. Please see | 344 // cached_minimize_button_x_delta_ member value. Please see |
| 345 // CacheMinimizeButtonDelta() for more details. | 345 // CacheMinimizeButtonDelta() for more details. |
| 346 DCHECK(cached_minimize_button_x_delta_); | 346 DCHECK(cached_minimize_button_x_delta_); |
| 347 | 347 |
| 348 RECT client_rect = {0}; | 348 RECT client_rect = {0}; |
| 349 GetClientRect(&client_rect); | 349 GetClientRect(GetNativeView(), &client_rect); |
| 350 | 350 |
| 351 if (base::i18n::IsRTL()) | 351 if (base::i18n::IsRTL()) |
| 352 return cached_minimize_button_x_delta_; | 352 return cached_minimize_button_x_delta_; |
| 353 else | 353 else |
| 354 return client_rect.right - cached_minimize_button_x_delta_; | 354 return client_rect.right - cached_minimize_button_x_delta_; |
| 355 } | 355 } |
| 356 | 356 |
| 357 void BrowserFrameWin::TabStripDisplayModeChanged() { | 357 void BrowserFrameWin::TabStripDisplayModeChanged() { |
| 358 UpdateDWMFrame(); | 358 UpdateDWMFrame(); |
| 359 } | 359 } |
| 360 | 360 |
| 361 void BrowserFrameWin::ButtonPressed(views::Button* sender, | 361 void BrowserFrameWin::ButtonPressed(views::Button* sender, |
| 362 const ui::Event& event) { | 362 const ui::Event& event) { |
| 363 HMODULE metro = base::win::GetMetroModule(); | 363 HMODULE metro = base::win::GetMetroModule(); |
| 364 if (!metro) | 364 if (!metro) |
| 365 return; | 365 return; |
| 366 // Tell the metro_driver to flip our window. This causes the current | 366 // Tell the metro_driver to flip our window. This causes the current |
| 367 // browser window to be hidden and the next window to be shown. | 367 // browser window to be hidden and the next window to be shown. |
| 368 static FlipFrameWindows flip_window_fn = reinterpret_cast<FlipFrameWindows>( | 368 static FlipFrameWindows flip_window_fn = reinterpret_cast<FlipFrameWindows>( |
| 369 ::GetProcAddress(metro, "FlipFrameWindows")); | 369 ::GetProcAddress(metro, "FlipFrameWindows")); |
| 370 if (flip_window_fn) | 370 if (flip_window_fn) |
| 371 flip_window_fn(); | 371 flip_window_fn(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 LRESULT BrowserFrameWin::OnWndProc(UINT message, | 374 bool BrowserFrameWin::HandleMSG(UINT message, |
| 375 WPARAM w_param, | 375 WPARAM w_param, |
| 376 LPARAM l_param) { | 376 LPARAM l_param, |
| 377 LRESULT* result) { |
| 377 static const UINT metro_navigation_search_message = | 378 static const UINT metro_navigation_search_message = |
| 378 RegisterWindowMessage(chrome::kMetroNavigationAndSearchMessage); | 379 RegisterWindowMessage(chrome::kMetroNavigationAndSearchMessage); |
| 379 | 380 |
| 380 static const UINT metro_get_current_tab_info_message = | 381 static const UINT metro_get_current_tab_info_message = |
| 381 RegisterWindowMessage(chrome::kMetroGetCurrentTabInfoMessage); | 382 RegisterWindowMessage(chrome::kMetroGetCurrentTabInfoMessage); |
| 382 | 383 |
| 383 if (message == metro_navigation_search_message) { | 384 if (message == metro_navigation_search_message) { |
| 384 HandleMetroNavSearchRequest(w_param, l_param); | 385 HandleMetroNavSearchRequest(w_param, l_param); |
| 385 } else if (message == metro_get_current_tab_info_message) { | 386 } else if (message == metro_get_current_tab_info_message) { |
| 386 GetMetroCurrentTabInfo(w_param); | 387 GetMetroCurrentTabInfo(w_param); |
| 387 } else if (message == WM_PRINT && base::win::IsMetroProcess()) { | 388 } else if (message == WM_PRINT && base::win::IsMetroProcess()) { |
| 388 // This message is sent by the AnimateWindow API which is used in metro | 389 // This message is sent by the AnimateWindow API which is used in metro |
| 389 // mode to flip between active chrome windows. | 390 // mode to flip between active chrome windows. |
| 390 RECT client_rect = {0}; | 391 RECT client_rect = {0}; |
| 391 ::GetClientRect(GetNativeView(), &client_rect); | 392 ::GetClientRect(GetNativeView(), &client_rect); |
| 392 HDC dest_dc = reinterpret_cast<HDC>(w_param); | 393 HDC dest_dc = reinterpret_cast<HDC>(w_param); |
| 393 DCHECK(dest_dc); | 394 DCHECK(dest_dc); |
| 394 HDC src_dc = ::GetDC(GetNativeView()); | 395 HDC src_dc = ::GetDC(GetNativeView()); |
| 395 ::BitBlt(dest_dc, 0, 0, client_rect.right - client_rect.left, | 396 ::BitBlt(dest_dc, 0, 0, client_rect.right - client_rect.left, |
| 396 client_rect.bottom - client_rect.top, src_dc, 0, 0, | 397 client_rect.bottom - client_rect.top, src_dc, 0, 0, |
| 397 SRCCOPY); | 398 SRCCOPY); |
| 398 ::ReleaseDC(GetNativeView(), src_dc); | 399 ::ReleaseDC(GetNativeView(), src_dc); |
| 399 return 0; | 400 *result = 0; |
| 401 return true; |
| 400 } | 402 } |
| 401 return views::NativeWidgetWin::OnWndProc(message, w_param, l_param); | 403 return false; |
| 402 } | 404 } |
| 403 | 405 |
| 404 /////////////////////////////////////////////////////////////////////////////// | 406 /////////////////////////////////////////////////////////////////////////////// |
| 405 // BrowserFrameWin, private: | 407 // BrowserFrameWin, private: |
| 406 | 408 |
| 407 void BrowserFrameWin::UpdateDWMFrame() { | 409 void BrowserFrameWin::UpdateDWMFrame() { |
| 408 // For "normal" windows on Aero, we always need to reset the glass area | 410 // For "normal" windows on Aero, we always need to reset the glass area |
| 409 // correctly, even if we're not currently showing the native frame (e.g. | 411 // correctly, even if we're not currently showing the native frame (e.g. |
| 410 // because a theme is showing), so we explicitly check for that case rather | 412 // because a theme is showing), so we explicitly check for that case rather |
| 411 // than checking browser_frame_->ShouldUseNativeFrame() here. Using that here | 413 // than checking browser_frame_->ShouldUseNativeFrame() here. Using that here |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 current_tab_info->url = base::win::LocalAllocAndCopyString( | 574 current_tab_info->url = base::win::LocalAllocAndCopyString( |
| 573 UTF8ToWide(current_tab->GetURL().spec())); | 575 UTF8ToWide(current_tab->GetURL().spec())); |
| 574 } | 576 } |
| 575 | 577 |
| 576 void BrowserFrameWin::CacheMinimizeButtonDelta() { | 578 void BrowserFrameWin::CacheMinimizeButtonDelta() { |
| 577 int minimize_offset = GetMinimizeButtonOffsetForWindow(GetNativeView()); | 579 int minimize_offset = GetMinimizeButtonOffsetForWindow(GetNativeView()); |
| 578 if (!minimize_offset) | 580 if (!minimize_offset) |
| 579 return; | 581 return; |
| 580 | 582 |
| 581 RECT rect = {0}; | 583 RECT rect = {0}; |
| 582 GetClientRect(&rect); | 584 GetClientRect(GetNativeView(), &rect); |
| 583 // Calculate and cache the value of the minimize button delta, i.e. the | 585 // Calculate and cache the value of the minimize button delta, i.e. the |
| 584 // offset to be applied to the left or right edge of the client rect | 586 // offset to be applied to the left or right edge of the client rect |
| 585 // depending on whether the language is RTL or not. | 587 // depending on whether the language is RTL or not. |
| 586 // This cached value is only used if the WM_GETTITLEBARINFOEX message fails | 588 // This cached value is only used if the WM_GETTITLEBARINFOEX message fails |
| 587 // to get the offset of the minimize button. | 589 // to get the offset of the minimize button. |
| 588 if (base::i18n::IsRTL()) | 590 if (base::i18n::IsRTL()) |
| 589 cached_minimize_button_x_delta_ = minimize_offset; | 591 cached_minimize_button_x_delta_ = minimize_offset; |
| 590 else | 592 else |
| 591 cached_minimize_button_x_delta_ = rect.right - minimize_offset; | 593 cached_minimize_button_x_delta_ = rect.right - minimize_offset; |
| 592 } | 594 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 603 | 605 |
| 604 //////////////////////////////////////////////////////////////////////////////// | 606 //////////////////////////////////////////////////////////////////////////////// |
| 605 // NativeBrowserFrame, public: | 607 // NativeBrowserFrame, public: |
| 606 | 608 |
| 607 // static | 609 // static |
| 608 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( | 610 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( |
| 609 BrowserFrame* browser_frame, | 611 BrowserFrame* browser_frame, |
| 610 BrowserView* browser_view) { | 612 BrowserView* browser_view) { |
| 611 return new BrowserFrameWin(browser_frame, browser_view); | 613 return new BrowserFrameWin(browser_frame, browser_view); |
| 612 } | 614 } |
| OLD | NEW |