Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2318)

Unified Diff: ash/frame/custom_frame_view_ash.cc

Issue 200483004: Show avatar icon on V2 app's frame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/frame/custom_frame_view_ash.cc
diff --git a/ash/frame/custom_frame_view_ash.cc b/ash/frame/custom_frame_view_ash.cc
index 615bc40d97cf5b225d5615eecbbe148c77985d94..196f9016519cffa76c8fdf177035ed62b0d99f79 100644
--- a/ash/frame/custom_frame_view_ash.cc
+++ b/ash/frame/custom_frame_view_ash.cc
@@ -10,7 +10,10 @@
#include "ash/frame/caption_buttons/frame_maximize_button_observer.h"
#include "ash/frame/default_header_painter.h"
#include "ash/frame/frame_border_hit_test_controller.h"
+#include "ash/frame/frame_util.h"
#include "ash/frame/header_painter.h"
+#include "ash/session_state_delegate.h"
+#include "ash/shell.h"
#include "ash/wm/immersive_fullscreen_controller.h"
#include "ash/wm/window_state.h"
#include "ash/wm/window_state_delegate.h"
@@ -20,9 +23,11 @@
#include "ui/aura/window.h"
#include "ui/aura/window_observer.h"
#include "ui/gfx/canvas.h"
+#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/size.h"
+#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
@@ -146,6 +151,8 @@ class CustomFrameViewAsh::HeaderView
// Returns the view's minimum width.
int GetMinimumWidth() const;
+ void UpdateAvatarIcon();
+
// views::View overrides:
virtual void Layout() OVERRIDE;
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
@@ -154,6 +161,10 @@ class CustomFrameViewAsh::HeaderView
return caption_button_container_;
}
+ views::View* avatar_icon() const {
+ return avatar_icon_;
+ }
+
private:
// ImmersiveFullscreenController::Delegate overrides:
virtual void OnImmersiveRevealStarted() OVERRIDE;
@@ -171,6 +182,8 @@ class CustomFrameViewAsh::HeaderView
// Helper for painting the header.
scoped_ptr<DefaultHeaderPainter> header_painter_;
+ views::ImageView* avatar_icon_;
+
// View which contains the window caption buttons.
FrameCaptionButtonContainerView* caption_button_container_;
@@ -191,6 +204,7 @@ class CustomFrameViewAsh::HeaderView
CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
: frame_(frame),
header_painter_(new ash::DefaultHeaderPainter),
+ avatar_icon_(NULL),
caption_button_container_(NULL),
maximize_bubble_(NULL),
fullscreen_visible_fraction_(0) {
@@ -209,6 +223,7 @@ CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
frame_maximize_button->AddObserver(this);
header_painter_->Init(frame_, this, NULL, caption_button_container_);
+ UpdateAvatarIcon();
}
CustomFrameViewAsh::HeaderView::~HeaderView() {
@@ -242,6 +257,33 @@ int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
return header_painter_->GetMinimumHeaderWidth();
}
+void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
+ SessionStateDelegate* delegate =
+ Shell::GetInstance()->session_state_delegate();
+ aura::Window* window = frame_->GetNativeView();
+ bool show = delegate->ShouldShowAvatar(window);
+ int icon_size = 0;
+ if (!show) {
+ if (!avatar_icon_)
+ return;
+ delete avatar_icon_;
+ avatar_icon_ = NULL;
+ } else {
+ gfx::ImageSkia image = GetAvatarImageForContext(
+ delegate->GetBrowserContextForWindow(window)).AsImageSkia();
+ DCHECK(!image.isNull());
+ DCHECK_EQ(image.width(), image.height());
+ if (!avatar_icon_) {
+ avatar_icon_ = new views::ImageView();
+ AddChildView(avatar_icon_);
+ }
+ avatar_icon_->SetImage(image);
+ icon_size = image.width();
+ }
+ header_painter_->UpdateWindowIcon(avatar_icon_, icon_size);
+ Layout();
+}
+
void CustomFrameViewAsh::HeaderView::Layout() {
header_painter_->LayoutHeader();
}
@@ -479,10 +521,20 @@ bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
return false;
}
+void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from,
+ bool is_visible) {
+ if (is_visible)
+ header_view_->UpdateAvatarIcon();
+}
+
views::View* CustomFrameViewAsh::GetHeaderView() {
return header_view_;
}
+const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
+ return header_view_->avatar_icon();
+}
+
////////////////////////////////////////////////////////////////////////////////
// CustomFrameViewAsh, private:

Powered by Google App Engine
This is Rietveld 408576698