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 28 matching lines...) Expand all Loading... |
39 #include "ui/base/models/simple_menu_model.h" | 39 #include "ui/base/models/simple_menu_model.h" |
40 #include "ui/base/resource/resource_bundle.h" | 40 #include "ui/base/resource/resource_bundle.h" |
41 #include "ui/base/theme_provider.h" | 41 #include "ui/base/theme_provider.h" |
42 #include "ui/gfx/font.h" | 42 #include "ui/gfx/font.h" |
43 #include "ui/views/controls/menu/native_menu_win.h" | 43 #include "ui/views/controls/menu/native_menu_win.h" |
44 #include "ui/views/views_delegate.h" | 44 #include "ui/views/views_delegate.h" |
45 #include "ui/views/widget/native_widget_win.h" | 45 #include "ui/views/widget/native_widget_win.h" |
46 #include "ui/views/widget/widget.h" | 46 #include "ui/views/widget/widget.h" |
47 #include "ui/views/window/non_client_view.h" | 47 #include "ui/views/window/non_client_view.h" |
48 #include "webkit/glue/window_open_disposition.h" | 48 #include "webkit/glue/window_open_disposition.h" |
| 49 #include "win8/util/win8_util.h" |
49 | 50 |
50 #pragma comment(lib, "dwmapi.lib") | 51 #pragma comment(lib, "dwmapi.lib") |
51 | 52 |
52 // static | 53 // static |
53 static const int kClientEdgeThickness = 3; | 54 static const int kClientEdgeThickness = 3; |
54 static const int kTabDragWindowAlpha = 200; | 55 static const int kTabDragWindowAlpha = 200; |
55 // We need to offset the DWMFrame into the toolbar so that the blackness | 56 // We need to offset the DWMFrame into the toolbar so that the blackness |
56 // doesn't show up on our rounded corners. | 57 // doesn't show up on our rounded corners. |
57 static const int kDWMFrameTopOffset = 3; | 58 static const int kDWMFrameTopOffset = 3; |
58 // If not -1, windows are shown with this state. | 59 // If not -1, windows are shown with this state. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 /////////////////////////////////////////////////////////////////////////////// | 96 /////////////////////////////////////////////////////////////////////////////// |
96 // BrowserFrameWin, public: | 97 // BrowserFrameWin, public: |
97 | 98 |
98 BrowserFrameWin::BrowserFrameWin(BrowserFrame* browser_frame, | 99 BrowserFrameWin::BrowserFrameWin(BrowserFrame* browser_frame, |
99 BrowserView* browser_view) | 100 BrowserView* browser_view) |
100 : views::NativeWidgetWin(browser_frame), | 101 : views::NativeWidgetWin(browser_frame), |
101 browser_view_(browser_view), | 102 browser_view_(browser_view), |
102 browser_frame_(browser_frame), | 103 browser_frame_(browser_frame), |
103 system_menu_delegate_(new SystemMenuModelDelegate(browser_view, | 104 system_menu_delegate_(new SystemMenuModelDelegate(browser_view, |
104 browser_view->browser())) { | 105 browser_view->browser())) { |
105 if (base::win::IsMetroProcess()) { | 106 if (win8::IsSingleWindowMetroMode()) { |
106 browser_view->SetWindowSwitcherButton( | 107 browser_view->SetWindowSwitcherButton( |
107 MakeWindowSwitcherButton(this, browser_view->IsOffTheRecord())); | 108 MakeWindowSwitcherButton(this, browser_view->IsOffTheRecord())); |
108 } | 109 } |
109 } | 110 } |
110 | 111 |
111 BrowserFrameWin::~BrowserFrameWin() { | 112 BrowserFrameWin::~BrowserFrameWin() { |
112 } | 113 } |
113 | 114 |
114 // static | 115 // static |
115 void BrowserFrameWin::SetShowState(int state) { | 116 void BrowserFrameWin::SetShowState(int state) { |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 GetMetroCurrentTabInfo(w_param); | 200 GetMetroCurrentTabInfo(w_param); |
200 return false; | 201 return false; |
201 } | 202 } |
202 | 203 |
203 switch (message) { | 204 switch (message) { |
204 case WM_ACTIVATE: | 205 case WM_ACTIVATE: |
205 if (LOWORD(w_param) != WA_INACTIVE) | 206 if (LOWORD(w_param) != WA_INACTIVE) |
206 minimize_button_metrics_.OnHWNDActivated(); | 207 minimize_button_metrics_.OnHWNDActivated(); |
207 return false; | 208 return false; |
208 case WM_PRINT: | 209 case WM_PRINT: |
209 if (base::win::IsMetroProcess()) { | 210 if (win8::IsSingleWindowMetroMode()) { |
210 // This message is sent by the AnimateWindow API which is used in metro | 211 // This message is sent by the AnimateWindow API which is used in metro |
211 // mode to flip between active chrome windows. | 212 // mode to flip between active chrome windows. |
212 RECT client_rect = {0}; | 213 RECT client_rect = {0}; |
213 ::GetClientRect(GetNativeView(), &client_rect); | 214 ::GetClientRect(GetNativeView(), &client_rect); |
214 HDC dest_dc = reinterpret_cast<HDC>(w_param); | 215 HDC dest_dc = reinterpret_cast<HDC>(w_param); |
215 DCHECK(dest_dc); | 216 DCHECK(dest_dc); |
216 HDC src_dc = ::GetDC(GetNativeView()); | 217 HDC src_dc = ::GetDC(GetNativeView()); |
217 ::BitBlt(dest_dc, 0, 0, client_rect.right - client_rect.left, | 218 ::BitBlt(dest_dc, 0, 0, client_rect.right - client_rect.left, |
218 client_rect.bottom - client_rect.top, src_dc, 0, 0, | 219 client_rect.bottom - client_rect.top, src_dc, 0, 0, |
219 SRCCOPY); | 220 SRCCOPY); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 304 |
304 void BrowserFrameWin::Close() { | 305 void BrowserFrameWin::Close() { |
305 CloseImmersiveFrame(); | 306 CloseImmersiveFrame(); |
306 views::NativeWidgetWin::Close(); | 307 views::NativeWidgetWin::Close(); |
307 } | 308 } |
308 | 309 |
309 void BrowserFrameWin::FrameTypeChanged() { | 310 void BrowserFrameWin::FrameTypeChanged() { |
310 // In Windows 8 metro mode the frame type is set to FRAME_TYPE_FORCE_CUSTOM | 311 // In Windows 8 metro mode the frame type is set to FRAME_TYPE_FORCE_CUSTOM |
311 // by default. We reset it back to FRAME_TYPE_DEFAULT to ensure that we | 312 // by default. We reset it back to FRAME_TYPE_DEFAULT to ensure that we |
312 // don't end up defaulting to BrowserNonClientFrameView in all cases. | 313 // don't end up defaulting to BrowserNonClientFrameView in all cases. |
313 if (base::win::IsMetroProcess()) | 314 if (win8::IsSingleWindowMetroMode()) |
314 browser_frame_->set_frame_type(views::Widget::FRAME_TYPE_DEFAULT); | 315 browser_frame_->set_frame_type(views::Widget::FRAME_TYPE_DEFAULT); |
315 | 316 |
316 views::NativeWidgetWin::FrameTypeChanged(); | 317 views::NativeWidgetWin::FrameTypeChanged(); |
317 | 318 |
318 // In Windows 8 metro mode we call Show on the BrowserFrame instance to | 319 // In Windows 8 metro mode we call Show on the BrowserFrame instance to |
319 // ensure that the window can be styled appropriately, i.e. no sysmenu, | 320 // ensure that the window can be styled appropriately, i.e. no sysmenu, |
320 // etc. | 321 // etc. |
321 if (base::win::IsMetroProcess()) | 322 if (win8::IsSingleWindowMetroMode()) |
322 Show(); | 323 Show(); |
323 } | 324 } |
324 | 325 |
325 void BrowserFrameWin::SetFullscreen(bool fullscreen) { | 326 void BrowserFrameWin::SetFullscreen(bool fullscreen) { |
326 if (base::win::IsMetroProcess()) { | 327 if (win8::IsSingleWindowMetroMode()) { |
327 HMODULE metro = base::win::GetMetroModule(); | 328 HMODULE metro = base::win::GetMetroModule(); |
328 if (metro) { | 329 if (metro) { |
329 MetroSetFullscreen set_full_screen = reinterpret_cast<MetroSetFullscreen>( | 330 MetroSetFullscreen set_full_screen = reinterpret_cast<MetroSetFullscreen>( |
330 ::GetProcAddress(metro, "SetFullscreen")); | 331 ::GetProcAddress(metro, "SetFullscreen")); |
331 DCHECK(set_full_screen); | 332 DCHECK(set_full_screen); |
332 if (set_full_screen) | 333 if (set_full_screen) |
333 set_full_screen(fullscreen); | 334 set_full_screen(fullscreen); |
334 } else { | 335 } else { |
335 NOTREACHED() << "Failed to get metro driver module"; | 336 NOTREACHED() << "Failed to get metro driver module"; |
336 } | 337 } |
337 } | 338 } |
338 views::NativeWidgetWin::SetFullscreen(fullscreen); | 339 views::NativeWidgetWin::SetFullscreen(fullscreen); |
339 } | 340 } |
340 | 341 |
341 void BrowserFrameWin::Activate() { | 342 void BrowserFrameWin::Activate() { |
342 // In Windows 8 metro mode we have only one window visible at any given time. | 343 // In Windows 8 metro mode we have only one window visible at any given time. |
343 // The Activate code path is typically called when a new browser window is | 344 // The Activate code path is typically called when a new browser window is |
344 // being activated. In metro we need to ensure that the window currently | 345 // being activated. In metro we need to ensure that the window currently |
345 // being displayed is hidden and the new window being activated becomes | 346 // being displayed is hidden and the new window being activated becomes |
346 // visible. This is achieved by calling AdjustFrameForImmersiveMode() | 347 // visible. This is achieved by calling AdjustFrameForImmersiveMode() |
347 // followed by ShowWindow(). | 348 // followed by ShowWindow(). |
348 if (base::win::IsMetroProcess()) { | 349 if (win8::IsSingleWindowMetroMode()) { |
349 AdjustFrameForImmersiveMode(); | 350 AdjustFrameForImmersiveMode(); |
350 ::ShowWindow(browser_frame_->GetNativeWindow(), SW_SHOWNORMAL); | 351 ::ShowWindow(browser_frame_->GetNativeWindow(), SW_SHOWNORMAL); |
351 } else { | 352 } else { |
352 views::NativeWidgetWin::Activate(); | 353 views::NativeWidgetWin::Activate(); |
353 } | 354 } |
354 } | 355 } |
355 | 356 |
356 | 357 |
357 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
358 // BrowserFrameWin, NativeBrowserFrame implementation: | 359 // BrowserFrameWin, NativeBrowserFrame implementation: |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 // BrowserFrame, public: | 599 // BrowserFrame, public: |
599 | 600 |
600 // static | 601 // static |
601 const gfx::Font& BrowserFrame::GetTitleFont() { | 602 const gfx::Font& BrowserFrame::GetTitleFont() { |
602 static gfx::Font* title_font = | 603 static gfx::Font* title_font = |
603 new gfx::Font(views::NativeWidgetWin::GetWindowTitleFont()); | 604 new gfx::Font(views::NativeWidgetWin::GetWindowTitleFont()); |
604 return *title_font; | 605 return *title_font; |
605 } | 606 } |
606 | 607 |
607 bool BrowserFrame::ShouldLeaveOffsetNearTopBorder() { | 608 bool BrowserFrame::ShouldLeaveOffsetNearTopBorder() { |
608 if (base::win::IsMetroProcess()) { | 609 if (win8::IsSingleWindowMetroMode()) { |
609 if (ui::GetDisplayLayout() == ui::LAYOUT_DESKTOP) | 610 if (ui::GetDisplayLayout() == ui::LAYOUT_DESKTOP) |
610 return false; | 611 return false; |
611 } | 612 } |
612 return !IsMaximized(); | 613 return !IsMaximized(); |
613 } | 614 } |
614 | 615 |
615 //////////////////////////////////////////////////////////////////////////////// | 616 //////////////////////////////////////////////////////////////////////////////// |
616 // NativeBrowserFrame, public: | 617 // NativeBrowserFrame, public: |
617 | 618 |
618 // static | 619 // static |
619 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( | 620 NativeBrowserFrame* NativeBrowserFrame::CreateNativeBrowserFrame( |
620 BrowserFrame* browser_frame, | 621 BrowserFrame* browser_frame, |
621 BrowserView* browser_view) { | 622 BrowserView* browser_view) { |
622 return new BrowserFrameWin(browser_frame, browser_view); | 623 return new BrowserFrameWin(browser_frame, browser_view); |
623 } | 624 } |
OLD | NEW |