browser_non_client_frame_view.cc revision 2a99a7e74a7f215066514fe81d2bfa6639d9eddd
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 3// found in the LICENSE file. 4 5#include "chrome/browser/ui/views/frame/browser_non_client_frame_view.h" 6 7#include "chrome/browser/browser_process.h" 8#include "chrome/browser/managed_mode/managed_mode.h" 9#include "chrome/browser/profiles/avatar_menu_model.h" 10#include "chrome/browser/profiles/profile.h" 11#include "chrome/browser/profiles/profile_info_cache.h" 12#include "chrome/browser/profiles/profile_manager.h" 13#include "chrome/browser/ui/views/avatar_menu_button.h" 14#include "chrome/browser/ui/views/frame/browser_view.h" 15#include "chrome/browser/ui/views/frame/taskbar_decorator.h" 16#include "grit/theme_resources.h" 17#include "ui/base/resource/resource_bundle.h" 18#include "ui/gfx/image/image.h" 19 20BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame, 21 BrowserView* browser_view) 22 : frame_(frame), 23 browser_view_(browser_view) { 24} 25 26BrowserNonClientFrameView::~BrowserNonClientFrameView() { 27} 28 29void BrowserNonClientFrameView::UpdateAvatarInfo() { 30 if (browser_view_->ShouldShowAvatar()) { 31 if (!avatar_button_.get()) { 32 avatar_button_.reset( 33 new AvatarMenuButton(browser_view_->browser(), 34 browser_view_->IsOffTheRecord())); 35 AddChildView(avatar_button_.get()); 36 frame_->GetRootView()->Layout(); 37 } 38 } else if (avatar_button_.get()) { 39 RemoveChildView(avatar_button_.get()); 40 avatar_button_.reset(); 41 frame_->GetRootView()->Layout(); 42 } 43 44 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 45 gfx::Image avatar; 46 string16 text; 47 bool is_gaia_picture = false; 48 if (browser_view_->IsOffTheRecord()) { 49 avatar = rb.GetImageNamed(browser_view_->GetOTRIconResourceID()); 50 } else if (ManagedMode::IsInManagedMode()) { 51 avatar = rb.GetImageNamed(IDR_MANAGED_MODE_AVATAR); 52 } else if (AvatarMenuModel::ShouldShowAvatarMenu()) { 53 ProfileInfoCache& cache = 54 g_browser_process->profile_manager()->GetProfileInfoCache(); 55 Profile* profile = browser_view_->browser()->profile(); 56 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); 57 if (index == std::string::npos) 58 return; 59 is_gaia_picture = 60 cache.IsUsingGAIAPictureOfProfileAtIndex(index) && 61 cache.GetGAIAPictureOfProfileAtIndex(index); 62 avatar = cache.GetAvatarIconOfProfileAtIndex(index); 63 text = cache.GetNameOfProfileAtIndex(index); 64 } 65 if (avatar_button_.get()) { 66 avatar_button_->SetAvatarIcon(avatar, is_gaia_picture); 67 if (!text.empty()) 68 avatar_button_->SetText(text); 69 } 70 71 // For popups and panels which don't have the avatar button, we still 72 // need to draw the taskbar decoration. 73 if (AvatarMenuModel::ShouldShowAvatarMenu() || 74 ManagedMode::IsInManagedMode()) { 75 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &avatar); 76 } else { 77 chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), NULL); 78 } 79} 80 81void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from, 82 bool is_visible) { 83 if (!is_visible) 84 return; 85 // The first time UpdateAvatarInfo() is called the window is not visible so 86 // DrawTaskBarDecoration() has no effect. Therefore we need to call it again 87 // once the window is visible. 88 UpdateAvatarInfo(); 89} 90