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/opaque_browser_frame_view.h" | 5 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/command_line.h" | |
11 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
12 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/profiles/profiles_state.h" | 14 #include "chrome/browser/profiles/profiles_state.h" |
16 #include "chrome/browser/themes/theme_properties.h" | 15 #include "chrome/browser/themes/theme_properties.h" |
17 #include "chrome/browser/ui/views/avatar_label.h" | 16 #include "chrome/browser/ui/views/avatar_label.h" |
18 #include "chrome/browser/ui/views/avatar_menu_button.h" | 17 #include "chrome/browser/ui/views/avatar_menu_button.h" |
19 #include "chrome/browser/ui/views/frame/browser_frame.h" | 18 #include "chrome/browser/ui/views/frame/browser_frame.h" |
20 #include "chrome/browser/ui/views/frame/browser_view.h" | 19 #include "chrome/browser/ui/views/frame/browser_view.h" |
21 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" | 20 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
22 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_speci
fic.h" | 21 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_speci
fic.h" |
23 #include "chrome/browser/ui/views/new_avatar_button.h" | 22 #include "chrome/browser/ui/views/new_avatar_button.h" |
24 #include "chrome/browser/ui/views/tab_icon_view.h" | 23 #include "chrome/browser/ui/views/tab_icon_view.h" |
25 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 24 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
26 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 25 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
27 #include "chrome/common/chrome_switches.h" | |
28 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/profile_management_switches.h" | 27 #include "chrome/common/profile_management_switches.h" |
30 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
31 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
32 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
33 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
34 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
35 #include "grit/ui_resources.h" | 33 #include "grit/ui_resources.h" |
36 #include "ui/base/accessibility/accessible_view_state.h" | 34 #include "ui/base/accessibility/accessible_view_state.h" |
37 #include "ui/base/hit_test.h" | 35 #include "ui/base/hit_test.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 new_avatar_button()->GetMirroredBounds().Contains(point))) | 217 new_avatar_button()->GetMirroredBounds().Contains(point))) |
220 return HTCLIENT; | 218 return HTCLIENT; |
221 | 219 |
222 int frame_component = frame()->client_view()->NonClientHitTest(point); | 220 int frame_component = frame()->client_view()->NonClientHitTest(point); |
223 | 221 |
224 // See if we're in the sysmenu region. We still have to check the tabstrip | 222 // See if we're in the sysmenu region. We still have to check the tabstrip |
225 // first so that clicks in a tab don't get treated as sysmenu clicks. | 223 // first so that clicks in a tab don't get treated as sysmenu clicks. |
226 gfx::Rect sysmenu_rect(IconBounds()); | 224 gfx::Rect sysmenu_rect(IconBounds()); |
227 // In maximized mode we extend the rect to the screen corner to take advantage | 225 // In maximized mode we extend the rect to the screen corner to take advantage |
228 // of Fitts' Law. | 226 // of Fitts' Law. |
229 if (layout_->IsTitleBarCondensed()) | 227 if (frame()->IsMaximized()) |
230 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); | 228 sysmenu_rect.SetRect(0, 0, sysmenu_rect.right(), sysmenu_rect.bottom()); |
231 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); | 229 sysmenu_rect.set_x(GetMirroredXForRect(sysmenu_rect)); |
232 if (sysmenu_rect.Contains(point)) | 230 if (sysmenu_rect.Contains(point)) |
233 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; | 231 return (frame_component == HTCLIENT) ? HTCLIENT : HTSYSMENU; |
234 | 232 |
235 if (frame_component != HTNOWHERE) | 233 if (frame_component != HTNOWHERE) |
236 return frame_component; | 234 return frame_component; |
237 | 235 |
238 // Then see if the point is within any of the window controls. | 236 // Then see if the point is within any of the window controls. |
239 if (close_button_ && close_button_->visible() && | 237 if (close_button_ && close_button_->visible() && |
(...skipping 18 matching lines...) Expand all Loading... |
258 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, | 256 NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, |
259 delegate->CanResize()); | 257 delegate->CanResize()); |
260 // Fall back to the caption if no other component matches. | 258 // Fall back to the caption if no other component matches. |
261 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; | 259 return (window_component == HTNOWHERE) ? HTCAPTION : window_component; |
262 } | 260 } |
263 | 261 |
264 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size, | 262 void OpaqueBrowserFrameView::GetWindowMask(const gfx::Size& size, |
265 gfx::Path* window_mask) { | 263 gfx::Path* window_mask) { |
266 DCHECK(window_mask); | 264 DCHECK(window_mask); |
267 | 265 |
268 if (layout_->IsTitleBarCondensed() || frame()->IsFullscreen()) | 266 if (frame()->IsMaximized() || frame()->IsFullscreen()) |
269 return; | 267 return; |
270 | 268 |
271 views::GetDefaultWindowMask(size, window_mask); | 269 views::GetDefaultWindowMask(size, window_mask); |
272 } | 270 } |
273 | 271 |
274 void OpaqueBrowserFrameView::ResetWindowControls() { | 272 void OpaqueBrowserFrameView::ResetWindowControls() { |
275 if (!OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons()) | 273 if (!OpaqueBrowserFrameViewLayout::ShouldAddDefaultCaptionButtons()) |
276 return; | 274 return; |
277 restore_button_->SetState(views::CustomButton::STATE_NORMAL); | 275 restore_button_->SetState(views::CustomButton::STATE_NORMAL); |
278 minimize_button_->SetState(views::CustomButton::STATE_NORMAL); | 276 minimize_button_->SetState(views::CustomButton::STATE_NORMAL); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 default: | 420 default: |
423 NOTREACHED() << "Got a notification we didn't register for!"; | 421 NOTREACHED() << "Got a notification we didn't register for!"; |
424 break; | 422 break; |
425 } | 423 } |
426 } | 424 } |
427 | 425 |
428 /////////////////////////////////////////////////////////////////////////////// | 426 /////////////////////////////////////////////////////////////////////////////// |
429 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: | 427 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: |
430 | 428 |
431 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { | 429 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { |
432 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
433 // If using the system title bar, we do not want to show a second title bar | |
434 // inside the client area. | |
435 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseSystemTitleBar)) | |
436 return false; | |
437 #endif | |
438 | |
439 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 430 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
440 return platform_observer_->ShouldShowTitleBar() && delegate && | 431 return platform_observer_->ShouldShowTitleBar() && delegate && |
441 delegate->ShouldShowWindowIcon(); | 432 delegate->ShouldShowWindowIcon(); |
442 } | 433 } |
443 | 434 |
444 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const { | 435 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const { |
445 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
446 // If using the system title bar, we do not want to show a second title bar | |
447 // inside the client area. | |
448 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseSystemTitleBar)) | |
449 return false; | |
450 #endif | |
451 | |
452 // |delegate| may be NULL if called from callback of InputMethodChanged while | 436 // |delegate| may be NULL if called from callback of InputMethodChanged while |
453 // a window is being destroyed. | 437 // a window is being destroyed. |
454 // See more discussion at http://crosbug.com/8958 | 438 // See more discussion at http://crosbug.com/8958 |
455 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 439 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
456 return platform_observer_->ShouldShowTitleBar() && delegate && | 440 return platform_observer_->ShouldShowTitleBar() && delegate && |
457 delegate->ShouldShowWindowTitle(); | 441 delegate->ShouldShowWindowTitle(); |
458 } | 442 } |
459 | 443 |
460 base::string16 OpaqueBrowserFrameView::GetWindowTitle() const { | 444 base::string16 OpaqueBrowserFrameView::GetWindowTitle() const { |
461 return frame()->widget_delegate()->GetWindowTitle(); | 445 return frame()->widget_delegate()->GetWindowTitle(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 return s; | 515 return s; |
532 } | 516 } |
533 | 517 |
534 /////////////////////////////////////////////////////////////////////////////// | 518 /////////////////////////////////////////////////////////////////////////////// |
535 // OpaqueBrowserFrameView, views::View overrides: | 519 // OpaqueBrowserFrameView, views::View overrides: |
536 | 520 |
537 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { | 521 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { |
538 if (frame()->IsFullscreen()) | 522 if (frame()->IsFullscreen()) |
539 return; // Nothing is visible, so don't bother to paint. | 523 return; // Nothing is visible, so don't bother to paint. |
540 | 524 |
541 if (layout_->IsTitleBarCondensed()) | 525 if (frame()->IsMaximized()) |
542 PaintMaximizedFrameBorder(canvas); | 526 PaintMaximizedFrameBorder(canvas); |
543 else | 527 else |
544 PaintRestoredFrameBorder(canvas); | 528 PaintRestoredFrameBorder(canvas); |
545 | 529 |
546 // The window icon and title are painted by their respective views. | 530 // The window icon and title are painted by their respective views. |
547 /* TODO(pkasting): If this window is active, we should also draw a drop | 531 /* TODO(pkasting): If this window is active, we should also draw a drop |
548 * shadow on the title. This is tricky, because we don't want to hardcode a | 532 * shadow on the title. This is tricky, because we don't want to hardcode a |
549 * shadow color (since we want to work with various themes), but we can't | 533 * shadow color (since we want to work with various themes), but we can't |
550 * alpha-blend either (since the Windows text APIs don't really do this). | 534 * alpha-blend either (since the Windows text APIs don't really do this). |
551 * So we'd need to sample the background color at the right location and | 535 * So we'd need to sample the background color at the right location and |
552 * synthesize a good shadow color. */ | 536 * synthesize a good shadow color. */ |
553 | 537 |
554 if (browser_view()->IsToolbarVisible()) | 538 if (browser_view()->IsToolbarVisible()) |
555 PaintToolbarBackground(canvas); | 539 PaintToolbarBackground(canvas); |
556 if (!layout_->IsTitleBarCondensed()) | 540 if (!frame()->IsMaximized()) |
557 PaintRestoredClientEdge(canvas); | 541 PaintRestoredClientEdge(canvas); |
558 } | 542 } |
559 | 543 |
560 /////////////////////////////////////////////////////////////////////////////// | 544 /////////////////////////////////////////////////////////////////////////////// |
561 // OpaqueBrowserFrameView, private: | 545 // OpaqueBrowserFrameView, private: |
562 | 546 |
563 views::ImageButton* OpaqueBrowserFrameView::InitWindowCaptionButton( | 547 views::ImageButton* OpaqueBrowserFrameView::InitWindowCaptionButton( |
564 int normal_image_id, | 548 int normal_image_id, |
565 int hot_image_id, | 549 int hot_image_id, |
566 int pushed_image_id, | 550 int pushed_image_id, |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
910 | 894 |
911 int OpaqueBrowserFrameView::GetTopAreaHeight() const { | 895 int OpaqueBrowserFrameView::GetTopAreaHeight() const { |
912 gfx::ImageSkia* frame_image = GetFrameImage(); | 896 gfx::ImageSkia* frame_image = GetFrameImage(); |
913 int top_area_height = frame_image->height(); | 897 int top_area_height = frame_image->height(); |
914 if (browser_view()->IsTabStripVisible()) { | 898 if (browser_view()->IsTabStripVisible()) { |
915 top_area_height = std::max(top_area_height, | 899 top_area_height = std::max(top_area_height, |
916 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); | 900 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); |
917 } | 901 } |
918 return top_area_height; | 902 return top_area_height; |
919 } | 903 } |
OLD | NEW |