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