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/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "chrome/browser/chrome_notification_types.h" | |
14 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
15 #include "chrome/browser/signin/signin_header_helper.h" | 14 #include "chrome/browser/signin/signin_header_helper.h" |
16 #include "chrome/browser/themes/theme_properties.h" | 15 #include "chrome/browser/themes/theme_properties.h" |
17 #include "chrome/browser/ui/views/frame/browser_frame.h" | 16 #include "chrome/browser/ui/views/frame/browser_frame.h" |
18 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
19 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" | 18 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_layout.h" |
20 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_speci
fic.h" | 19 #include "chrome/browser/ui/views/frame/opaque_browser_frame_view_platform_speci
fic.h" |
21 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" | 20 #include "chrome/browser/ui/views/profiles/avatar_menu_button.h" |
22 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" | 21 #include "chrome/browser/ui/views/profiles/new_avatar_button.h" |
23 #include "chrome/browser/ui/views/tab_icon_view.h" | 22 #include "chrome/browser/ui/views/tab_icon_view.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 window_title_ = new views::Label( | 139 window_title_ = new views::Label( |
141 browser_view->GetWindowTitle(), | 140 browser_view->GetWindowTitle(), |
142 gfx::FontList(BrowserFrame::GetTitleFontList())); | 141 gfx::FontList(BrowserFrame::GetTitleFontList())); |
143 window_title_->SetVisible(browser_view->ShouldShowWindowTitle()); | 142 window_title_->SetVisible(browser_view->ShouldShowWindowTitle()); |
144 window_title_->SetEnabledColor(SK_ColorWHITE); | 143 window_title_->SetEnabledColor(SK_ColorWHITE); |
145 window_title_->SetSubpixelRenderingEnabled(false); | 144 window_title_->SetSubpixelRenderingEnabled(false); |
146 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 145 window_title_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
147 window_title_->set_id(VIEW_ID_WINDOW_TITLE); | 146 window_title_->set_id(VIEW_ID_WINDOW_TITLE); |
148 AddChildView(window_title_); | 147 AddChildView(window_title_); |
149 | 148 |
150 if (browser_view->IsRegularOrGuestSession() && switches::IsNewAvatarMenu()) | 149 UpdateAvatar(); |
151 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON); | |
152 else | |
153 UpdateAvatarInfo(); | |
154 | |
155 if (!browser_view->IsOffTheRecord()) { | |
156 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
157 content::NotificationService::AllSources()); | |
158 } | |
159 | 150 |
160 platform_observer_.reset(OpaqueBrowserFrameViewPlatformSpecific::Create( | 151 platform_observer_.reset(OpaqueBrowserFrameViewPlatformSpecific::Create( |
161 this, layout_, browser_view->browser()->profile())); | 152 this, layout_, browser_view->browser()->profile())); |
162 } | 153 } |
163 | 154 |
164 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { | 155 OpaqueBrowserFrameView::~OpaqueBrowserFrameView() { |
165 } | 156 } |
166 | 157 |
167 /////////////////////////////////////////////////////////////////////////////// | 158 /////////////////////////////////////////////////////////////////////////////// |
168 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation: | 159 // OpaqueBrowserFrameView, BrowserNonClientFrameView implementation: |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() { | 358 gfx::ImageSkia OpaqueBrowserFrameView::GetFaviconForTabIconView() { |
368 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 359 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
369 if (!delegate) { | 360 if (!delegate) { |
370 LOG(WARNING) << "delegate is null, returning safe default."; | 361 LOG(WARNING) << "delegate is null, returning safe default."; |
371 return gfx::ImageSkia(); | 362 return gfx::ImageSkia(); |
372 } | 363 } |
373 return delegate->GetWindowIcon(); | 364 return delegate->GetWindowIcon(); |
374 } | 365 } |
375 | 366 |
376 /////////////////////////////////////////////////////////////////////////////// | 367 /////////////////////////////////////////////////////////////////////////////// |
377 // OpaqueBrowserFrameView, protected: | |
378 | |
379 void OpaqueBrowserFrameView::Observe( | |
380 int type, | |
381 const content::NotificationSource& source, | |
382 const content::NotificationDetails& details) { | |
383 switch (type) { | |
384 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: | |
385 if (browser_view() ->IsRegularOrGuestSession() && | |
386 switches::IsNewAvatarMenu()) { | |
387 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON); | |
388 } else { | |
389 UpdateAvatarInfo(); | |
390 } | |
391 break; | |
392 default: | |
393 NOTREACHED() << "Got a notification we didn't register for!"; | |
394 break; | |
395 } | |
396 } | |
397 | |
398 /////////////////////////////////////////////////////////////////////////////// | |
399 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: | 368 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: |
400 | 369 |
401 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { | 370 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { |
402 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 371 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
403 return ShouldShowWindowTitleBar() && delegate && | 372 return ShouldShowWindowTitleBar() && delegate && |
404 delegate->ShouldShowWindowIcon(); | 373 delegate->ShouldShowWindowIcon(); |
405 } | 374 } |
406 | 375 |
407 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const { | 376 bool OpaqueBrowserFrameView::ShouldShowWindowTitle() const { |
408 // |delegate| may be null if called from callback of InputMethodChanged while | 377 // |delegate| may be null if called from callback of InputMethodChanged while |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 int OpaqueBrowserFrameView::GetTabStripHeight() const { | 440 int OpaqueBrowserFrameView::GetTabStripHeight() const { |
472 return browser_view()->GetTabStripHeight(); | 441 return browser_view()->GetTabStripHeight(); |
473 } | 442 } |
474 | 443 |
475 gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const { | 444 gfx::Size OpaqueBrowserFrameView::GetTabstripPreferredSize() const { |
476 gfx::Size s = browser_view()->tabstrip()->GetPreferredSize(); | 445 gfx::Size s = browser_view()->tabstrip()->GetPreferredSize(); |
477 return s; | 446 return s; |
478 } | 447 } |
479 | 448 |
480 /////////////////////////////////////////////////////////////////////////////// | 449 /////////////////////////////////////////////////////////////////////////////// |
481 // OpaqueBrowserFrameView, views::View overrides: | 450 // OpaqueBrowserFrameView, protected: |
482 | 451 |
| 452 // views::View: |
483 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { | 453 void OpaqueBrowserFrameView::OnPaint(gfx::Canvas* canvas) { |
484 if (frame()->IsFullscreen()) | 454 if (frame()->IsFullscreen()) |
485 return; // Nothing is visible, so don't bother to paint. | 455 return; // Nothing is visible, so don't bother to paint. |
486 | 456 |
487 if (layout_->IsTitleBarCondensed()) | 457 if (layout_->IsTitleBarCondensed()) |
488 PaintMaximizedFrameBorder(canvas); | 458 PaintMaximizedFrameBorder(canvas); |
489 else | 459 else |
490 PaintRestoredFrameBorder(canvas); | 460 PaintRestoredFrameBorder(canvas); |
491 | 461 |
492 // The window icon and title are painted by their respective views. | 462 // The window icon and title are painted by their respective views. |
493 /* TODO(pkasting): If this window is active, we should also draw a drop | 463 /* TODO(pkasting): If this window is active, we should also draw a drop |
494 * shadow on the title. This is tricky, because we don't want to hardcode a | 464 * shadow on the title. This is tricky, because we don't want to hardcode a |
495 * shadow color (since we want to work with various themes), but we can't | 465 * shadow color (since we want to work with various themes), but we can't |
496 * alpha-blend either (since the Windows text APIs don't really do this). | 466 * alpha-blend either (since the Windows text APIs don't really do this). |
497 * So we'd need to sample the background color at the right location and | 467 * So we'd need to sample the background color at the right location and |
498 * synthesize a good shadow color. */ | 468 * synthesize a good shadow color. */ |
499 | 469 |
500 if (browser_view()->IsToolbarVisible()) | 470 if (browser_view()->IsToolbarVisible()) |
501 PaintToolbarBackground(canvas); | 471 PaintToolbarBackground(canvas); |
502 if (!layout_->IsTitleBarCondensed()) | 472 if (!layout_->IsTitleBarCondensed()) |
503 PaintRestoredClientEdge(canvas); | 473 PaintRestoredClientEdge(canvas); |
504 } | 474 } |
505 | 475 |
| 476 // BrowserNonClientFrameView: |
| 477 void OpaqueBrowserFrameView::UpdateNewStyleAvatar() { |
| 478 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON); |
| 479 } |
| 480 |
506 /////////////////////////////////////////////////////////////////////////////// | 481 /////////////////////////////////////////////////////////////////////////////// |
507 // OpaqueBrowserFrameView, private: | 482 // OpaqueBrowserFrameView, private: |
508 | 483 |
509 // views::NonClientFrameView: | 484 // views::NonClientFrameView: |
510 bool OpaqueBrowserFrameView::DoesIntersectRect(const views::View* target, | 485 bool OpaqueBrowserFrameView::DoesIntersectRect(const views::View* target, |
511 const gfx::Rect& rect) const { | 486 const gfx::Rect& rect) const { |
512 CHECK_EQ(target, this); | 487 CHECK_EQ(target, this); |
513 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) { | 488 if (!views::ViewTargeterDelegate::DoesIntersectRect(this, rect)) { |
514 // |rect| is outside OpaqueBrowserFrameView's bounds. | 489 // |rect| is outside OpaqueBrowserFrameView's bounds. |
515 return false; | 490 return false; |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 | 904 |
930 int OpaqueBrowserFrameView::GetTopAreaHeight() const { | 905 int OpaqueBrowserFrameView::GetTopAreaHeight() const { |
931 gfx::ImageSkia* frame_image = GetFrameImage(); | 906 gfx::ImageSkia* frame_image = GetFrameImage(); |
932 int top_area_height = frame_image->height(); | 907 int top_area_height = frame_image->height(); |
933 if (browser_view()->IsTabStripVisible()) { | 908 if (browser_view()->IsTabStripVisible()) { |
934 top_area_height = std::max(top_area_height, | 909 top_area_height = std::max(top_area_height, |
935 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); | 910 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); |
936 } | 911 } |
937 return top_area_height; | 912 return top_area_height; |
938 } | 913 } |
OLD | NEW |