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(this, NewAvatarButton::THEMED_BUTTON); |
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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 if (!delegate) { | 353 if (!delegate) { |
363 LOG(WARNING) << "delegate is null, returning safe default."; | 354 LOG(WARNING) << "delegate is null, returning safe default."; |
364 return gfx::ImageSkia(); | 355 return gfx::ImageSkia(); |
365 } | 356 } |
366 return delegate->GetWindowIcon(); | 357 return delegate->GetWindowIcon(); |
367 } | 358 } |
368 | 359 |
369 /////////////////////////////////////////////////////////////////////////////// | 360 /////////////////////////////////////////////////////////////////////////////// |
370 // OpaqueBrowserFrameView, protected: | 361 // OpaqueBrowserFrameView, protected: |
371 | 362 |
372 void OpaqueBrowserFrameView::Observe( | 363 void OpaqueBrowserFrameView::OnProfileAdded( |
373 int type, | 364 const base::FilePath& profile_path) { |
374 const content::NotificationSource& source, | 365 UpdateAvatar(this, NewAvatarButton::THEMED_BUTTON); |
375 const content::NotificationDetails& details) { | 366 } |
376 switch (type) { | 367 |
377 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: | 368 void OpaqueBrowserFrameView::OnProfileWasRemoved( |
378 if (browser_view() ->IsRegularOrGuestSession() && | 369 const base::FilePath& profile_path, |
379 switches::IsNewAvatarMenu()) { | 370 const base::string16& profile_name) { |
380 UpdateNewStyleAvatarInfo(this, NewAvatarButton::THEMED_BUTTON); | 371 UpdateAvatar(this, NewAvatarButton::THEMED_BUTTON); |
381 } else { | 372 } |
382 UpdateAvatarInfo(); | 373 |
383 } | 374 void OpaqueBrowserFrameView::OnProfileNameChanged( |
384 break; | 375 const base::FilePath& profile_path, |
385 default: | 376 const base::string16& old_profile_name) { |
386 NOTREACHED() << "Got a notification we didn't register for!"; | 377 UpdateAvatar(this, NewAvatarButton::THEMED_BUTTON); |
387 break; | 378 } |
388 } | 379 |
| 380 void OpaqueBrowserFrameView::OnProfileAvatarChanged( |
| 381 const base::FilePath& profile_path) { |
| 382 // Profile avatars are only displayed in the old UI or incognito. |
| 383 if (browser_view()->IsOffTheRecord() || !switches::IsNewAvatarMenu()) |
| 384 UpdateAvatarInfo(); |
389 } | 385 } |
390 | 386 |
391 /////////////////////////////////////////////////////////////////////////////// | 387 /////////////////////////////////////////////////////////////////////////////// |
392 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: | 388 // OpaqueBrowserFrameView, OpaqueBrowserFrameViewLayoutDelegate implementation: |
393 | 389 |
394 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { | 390 bool OpaqueBrowserFrameView::ShouldShowWindowIcon() const { |
395 views::WidgetDelegate* delegate = frame()->widget_delegate(); | 391 views::WidgetDelegate* delegate = frame()->widget_delegate(); |
396 return ShouldShowWindowTitleBar() && delegate && | 392 return ShouldShowWindowTitleBar() && delegate && |
397 delegate->ShouldShowWindowIcon(); | 393 delegate->ShouldShowWindowIcon(); |
398 } | 394 } |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 | 918 |
923 int OpaqueBrowserFrameView::GetTopAreaHeight() const { | 919 int OpaqueBrowserFrameView::GetTopAreaHeight() const { |
924 gfx::ImageSkia* frame_image = GetFrameImage(); | 920 gfx::ImageSkia* frame_image = GetFrameImage(); |
925 int top_area_height = frame_image->height(); | 921 int top_area_height = frame_image->height(); |
926 if (browser_view()->IsTabStripVisible()) { | 922 if (browser_view()->IsTabStripVisible()) { |
927 top_area_height = std::max(top_area_height, | 923 top_area_height = std::max(top_area_height, |
928 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); | 924 GetBoundsForTabStrip(browser_view()->tabstrip()).bottom()); |
929 } | 925 } |
930 return top_area_height; | 926 return top_area_height; |
931 } | 927 } |
OLD | NEW |