summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/ui/views/avatar_label.cc59
-rw-r--r--chrome/browser/ui/views/avatar_label.h43
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view.cc61
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view.h17
-rw-r--r--chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc1
-rw-r--r--chrome/browser/ui/views/frame/glass_browser_frame_view.cc11
-rw-r--r--chrome/browser/ui/views/frame/opaque_browser_frame_view.cc9
-rw-r--r--chrome/chrome_browser_ui.gypi2
8 files changed, 146 insertions, 57 deletions
diff --git a/chrome/browser/ui/views/avatar_label.cc b/chrome/browser/ui/views/avatar_label.cc
new file mode 100644
index 0000000..8a6465d
--- /dev/null
+++ b/chrome/browser/ui/views/avatar_label.cc
@@ -0,0 +1,59 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/views/avatar_label.h"
+
+#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "grit/generated_resources.h"
+#include "ui/base/events/event.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/theme_provider.h"
+#include "ui/gfx/point.h"
+#include "ui/gfx/rect.h"
+
+AvatarLabel::AvatarLabel(BrowserView* browser_view,
+ ui::ThemeProvider* theme_provider)
+ : TextButton(NULL,
+ l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL)),
+ browser_view_(browser_view),
+ theme_provider_(theme_provider) {
+ SetFont(ui::ResourceBundle::GetSharedInstance().GetFont(
+ ui::ResourceBundle::SmallFont));
+ ClearMaxTextSize();
+ views::TextButtonNativeThemeBorder* border =
+ new views::TextButtonNativeThemeBorder(this);
+ const int kHorizontalInset = 10;
+ const int kVerticalInset = 2;
+ border->SetInsets(gfx::Insets(
+ kVerticalInset, kHorizontalInset, kVerticalInset, kHorizontalInset));
+ set_border(border);
+ UpdateLabelStyle();
+}
+
+AvatarLabel::~AvatarLabel() {}
+
+bool AvatarLabel::OnMousePressed(const ui::MouseEvent& event) {
+ if (!TextButton::OnMousePressed(event))
+ return false;
+
+ browser_view_->ShowAvatarBubbleFromAvatarButton();
+ return true;
+}
+
+void AvatarLabel::GetExtraParams(ui::NativeTheme::ExtraParams* params) const {
+ TextButton::GetExtraParams(params);
+ params->button.background_color = theme_provider_->GetColor(
+ ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND);
+}
+
+void AvatarLabel::UpdateLabelStyle() {
+ SkColor color_label =
+ theme_provider_->GetColor(ThemeProperties::COLOR_MANAGED_USER_LABEL);
+ SetEnabledColor(color_label);
+ SchedulePaint();
+}
diff --git a/chrome/browser/ui/views/avatar_label.h b/chrome/browser/ui/views/avatar_label.h
new file mode 100644
index 0000000..4445663
--- /dev/null
+++ b/chrome/browser/ui/views/avatar_label.h
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_UI_VIEWS_AVATAR_LABEL_H_
+#define CHROME_BROWSER_UI_VIEWS_AVATAR_LABEL_H_
+
+#include "base/compiler_specific.h"
+#include "ui/views/controls/button/text_button.h"
+
+class BrowserView;
+
+namespace ui {
+class MouseEvent;
+class ThemeProvider;
+class NativeTheme;
+}
+
+// AvatarLabel
+//
+// A label used to display a string indicating that the current profile belongs
+// to a managed user.
+class AvatarLabel : public views::TextButton {
+ public:
+ AvatarLabel(BrowserView* browser_view, ui::ThemeProvider* theme_provider);
+ virtual ~AvatarLabel();
+
+ // views::TextButton:
+ virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
+ virtual void GetExtraParams(
+ ui::NativeTheme::ExtraParams* params) const OVERRIDE;
+
+ // Update the style of the label according to the provided theme.
+ void UpdateLabelStyle();
+
+ private:
+ BrowserView* browser_view_;
+ ui::ThemeProvider* theme_provider_;
+
+ DISALLOW_COPY_AND_ASSIGN(AvatarLabel);
+};
+
+#endif // CHROME_BROWSER_UI_VIEWS_AVATAR_LABEL_H_
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
index 049e266..d7e2f76 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view.cc
@@ -9,7 +9,7 @@
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/taskbar_decorator.h"
@@ -21,7 +21,6 @@
#include "ui/base/theme_provider.h"
#include "ui/gfx/image/image.h"
#include "ui/views/background.h"
-#include "ui/views/controls/label.h"
#if defined(ENABLE_MANAGED_USERS)
#include "chrome/browser/managed_mode/managed_user_service.h"
@@ -31,7 +30,9 @@
BrowserNonClientFrameView::BrowserNonClientFrameView(BrowserFrame* frame,
BrowserView* browser_view)
: frame_(frame),
- browser_view_(browser_view) {
+ browser_view_(browser_view),
+ avatar_button_(NULL),
+ avatar_label_(NULL) {
}
BrowserNonClientFrameView::~BrowserNonClientFrameView() {
@@ -48,54 +49,38 @@ void BrowserNonClientFrameView::VisibilityChanged(views::View* starting_from,
}
void BrowserNonClientFrameView::OnThemeChanged() {
- UpdateAvatarLabelStyle();
-}
-
-void BrowserNonClientFrameView::UpdateAvatarLabelStyle() {
- if (!avatar_label_.get())
- return;
-
- ui::ThemeProvider* tp = frame_->GetThemeProvider();
- SkColor color_background = tp->GetColor(
- ThemeProperties::COLOR_MANAGED_USER_LABEL_BACKGROUND);
- avatar_label_->set_background(
- views::Background::CreateSolidBackground(color_background));
- avatar_label_->SetBackgroundColor(color_background);
- SkColor color_label = tp->GetColor(
- ThemeProperties::COLOR_MANAGED_USER_LABEL);
- avatar_label_->SetEnabledColor(color_label);
+ if (avatar_label_)
+ avatar_label_->UpdateLabelStyle();
}
void BrowserNonClientFrameView::UpdateAvatarInfo() {
if (browser_view_->ShouldShowAvatar()) {
- if (!avatar_button_.get()) {
- avatar_button_.reset(
- new AvatarMenuButton(browser_view_->browser(),
- browser_view_->IsOffTheRecord()));
- AddChildView(avatar_button_.get());
+ if (!avatar_button_) {
+ avatar_button_ = new AvatarMenuButton(browser_view_->browser(),
+ browser_view_->IsOffTheRecord());
+ AddChildView(avatar_button_);
#if defined(ENABLE_MANAGED_USERS)
Profile* profile = browser_view_->browser()->profile();
ManagedUserService* service =
ManagedUserServiceFactory::GetForProfile(profile);
- if (service->ProfileIsManaged() && !avatar_label_.get()) {
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- avatar_label_.reset(new views::Label(
- l10n_util::GetStringUTF16(IDS_MANAGED_USER_AVATAR_LABEL),
- rb.GetFont(ui::ResourceBundle::BoldFont)));
- UpdateAvatarLabelStyle();
- AddChildView(avatar_label_.get());
+ if (service->ProfileIsManaged() && !avatar_label_) {
+ avatar_label_ =
+ new AvatarLabel(browser_view_, frame_->GetThemeProvider());
+ AddChildView(avatar_label_);
}
#endif
frame_->GetRootView()->Layout();
}
- } else if (avatar_button_.get()) {
+ } else if (avatar_button_) {
// The avatar label can just be there if there is also an avatar button.
- if (avatar_label_.get()) {
- RemoveChildView(avatar_label_.get());
- avatar_label_.reset();
+ if (avatar_label_) {
+ RemoveChildView(avatar_label_);
+ delete avatar_label_;
+ avatar_label_ = NULL;
}
- RemoveChildView(avatar_button_.get());
- avatar_button_.reset();
+ RemoveChildView(avatar_button_);
+ delete avatar_button_;
+ avatar_button_ = NULL;
frame_->GetRootView()->Layout();
}
@@ -118,7 +103,7 @@ void BrowserNonClientFrameView::UpdateAvatarInfo() {
avatar = cache.GetAvatarIconOfProfileAtIndex(index);
text = cache.GetNameOfProfileAtIndex(index);
}
- if (avatar_button_.get()) {
+ if (avatar_button_) {
avatar_button_->SetAvatarIcon(avatar, is_gaia_picture);
if (!text.empty())
avatar_button_->SetText(text);
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view.h b/chrome/browser/ui/views/frame/browser_non_client_frame_view.h
index 8f319a8..91a9b0d 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view.h
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view.h
@@ -5,17 +5,13 @@
#ifndef CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_FRAME_BROWSER_NON_CLIENT_FRAME_VIEW_H_
-#include "base/memory/scoped_ptr.h"
#include "ui/views/window/non_client_view.h"
+class AvatarLabel;
class AvatarMenuButton;
class BrowserFrame;
class BrowserView;
-namespace views {
-class Label;
-}
-
// A specialization of the NonClientFrameView object that provides additional
// Browser-specific methods.
class BrowserNonClientFrameView : public views::NonClientFrameView {
@@ -36,9 +32,9 @@ class BrowserNonClientFrameView : public views::NonClientFrameView {
BrowserNonClientFrameView(BrowserFrame* frame, BrowserView* browser_view);
virtual ~BrowserNonClientFrameView();
- AvatarMenuButton* avatar_button() const { return avatar_button_.get(); }
+ AvatarMenuButton* avatar_button() const { return avatar_button_; }
- views::Label* avatar_label() const { return avatar_label_.get(); }
+ AvatarLabel* avatar_label() const { return avatar_label_; }
// Returns the bounds within which the TabStrip should be laid out.
virtual gfx::Rect GetBoundsForTabStrip(views::View* tabstrip) const = 0;
@@ -63,9 +59,6 @@ class BrowserNonClientFrameView : public views::NonClientFrameView {
BrowserView* browser_view() const { return browser_view_; }
BrowserFrame* frame() const { return frame_; }
- // Determine the color of the label text and the label background.
- void UpdateAvatarLabelStyle();
-
// Updates the title and icon of the avatar button.
void UpdateAvatarInfo();
@@ -78,10 +71,10 @@ class BrowserNonClientFrameView : public views::NonClientFrameView {
// Menu button that displays that either the incognito icon or the profile
// icon. May be NULL for some frame styles.
- scoped_ptr<AvatarMenuButton> avatar_button_;
+ AvatarMenuButton* avatar_button_;
// Avatar label that is used for a managed user.
- scoped_ptr<views::Label> avatar_label_;
+ AvatarLabel* avatar_label_;
};
namespace chrome {
diff --git a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
index 28b2be3..523a456 100644
--- a/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
+++ b/chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.cc
@@ -11,6 +11,7 @@
#include "chrome/browser/ui/ash/chrome_shell_delegate.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/immersive_fullscreen_configuration.h"
+#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
diff --git a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
index a744bc0..f1d8ba5 100644
--- a/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
+++ b/chrome/browser/ui/views/frame/glass_browser_frame_view.cc
@@ -11,6 +11,7 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/tabs/tab.h"
@@ -71,7 +72,7 @@ const int kNewTabCaptionMaximizedSpacing = 16;
// is no avatar icon.
const int kTabStripIndent = -6;
-}
+} // namespace
///////////////////////////////////////////////////////////////////////////////
// GlassBrowserFrameView, public:
@@ -206,9 +207,11 @@ int GlassBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
if (!browser_view()->IsBrowserTypeNormal() || !bounds().Contains(point))
return HTNOWHERE;
- // See if the point is within the avatar menu button.
- if (avatar_button() &&
- avatar_button()->GetMirroredBounds().Contains(point))
+ // See if the point is within the avatar menu button or within the avatar
+ // label.
+ if ((avatar_button() &&
+ avatar_button()->GetMirroredBounds().Contains(point)) ||
+ (avatar_label() && avatar_label()->GetMirroredBounds().Contains(point)))
return HTCLIENT;
int frame_component = frame()->client_view()->NonClientHitTest(point);
diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
index d77399c..c4bbf28 100644
--- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
+++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc
@@ -12,6 +12,7 @@
#include "base/prefs/pref_service.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/themes/theme_properties.h"
+#include "chrome/browser/ui/views/avatar_label.h"
#include "chrome/browser/ui/views/avatar_menu_button.h"
#include "chrome/browser/ui/views/frame/browser_frame.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
@@ -321,9 +322,11 @@ int OpaqueBrowserFrameView::NonClientHitTest(const gfx::Point& point) {
if (!bounds().Contains(point))
return HTNOWHERE;
- // See if the point is within the avatar menu button.
- if (avatar_button() &&
- avatar_button()->GetMirroredBounds().Contains(point))
+ // See if the point is within the avatar menu button or within the avatar
+ // label.
+ if ((avatar_button() &&
+ avatar_button()->GetMirroredBounds().Contains(point)) ||
+ (avatar_label() && avatar_label()->GetMirroredBounds().Contains(point)))
return HTCLIENT;
int frame_component = frame()->client_view()->NonClientHitTest(point);
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index a506350..d55bcfd 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -1533,6 +1533,8 @@
'browser/ui/views/avatar_menu_bubble_view.h',
'browser/ui/views/avatar_menu_button.cc',
'browser/ui/views/avatar_menu_button.h',
+ 'browser/ui/views/avatar_label.cc',
+ 'browser/ui/views/avatar_label.cc',
'browser/ui/views/bookmarks/bookmark_bar_instructions_view.cc',
'browser/ui/views/bookmarks/bookmark_bar_instructions_view.h',
'browser/ui/views/bookmarks/bookmark_bar_view.cc',