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 964020b8a48c9cbe0b3492e30bd5e3b5ef243ed6..beaf508c99d64b561bc585762f250a1d40dd830e 100644 |
--- a/ash/frame/custom_frame_view_ash.cc |
+++ b/ash/frame/custom_frame_view_ash.cc |
@@ -9,7 +9,10 @@ |
#include "ash/frame/caption_buttons/frame_maximize_button.h" |
#include "ash/frame/caption_buttons/frame_maximize_button_observer.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" |
@@ -22,9 +25,11 @@ |
#include "ui/aura/window_observer.h" |
#include "ui/gfx/canvas.h" |
#include "ui/gfx/font_list.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/native_widget_aura.h" |
#include "ui/views/widget/widget.h" |
@@ -156,6 +161,11 @@ class CustomFrameViewAsh::HeaderView |
// Returns the view's minimum width. |
int GetMinimumWidth() const; |
+ // Updates the avatar icon based on the current state |
+ // of the SessionStateDelegate::ShouldShowAvatar and |
+ // SessionStateDelegate::GetUserImage. |
+ void UpdateAvatarIcon(); |
+ |
// views::View overrides: |
virtual void Layout() OVERRIDE; |
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
@@ -164,6 +174,10 @@ class CustomFrameViewAsh::HeaderView |
return header_painter_.get(); |
} |
+ views::View* avatar_icon() const { |
+ return avatar_icon_; |
+ } |
+ |
private: |
// ImmersiveFullscreenController::Delegate overrides: |
virtual void OnImmersiveRevealStarted() OVERRIDE; |
@@ -178,6 +192,8 @@ class CustomFrameViewAsh::HeaderView |
// The widget that the caption buttons act on. |
views::Widget* frame_; |
+ views::ImageView* avatar_icon_; |
+ |
// Helper for painting the header. |
scoped_ptr<HeaderPainter> header_painter_; |
@@ -200,6 +216,7 @@ class CustomFrameViewAsh::HeaderView |
CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) |
: frame_(frame), |
+ avatar_icon_(NULL), |
header_painter_(new ash::HeaderPainter), |
caption_button_container_(NULL), |
maximize_bubble_(NULL), |
@@ -255,6 +272,32 @@ 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); |
+ if (!show && avatar_icon_) { |
Mr4D (OOO till 08-26)
2014/03/14 22:01:30
This is confusing to read. Why not:
if (!delegate
oshima
2014/03/15 01:32:32
you're absolutely right. fixed.
|
+ delete avatar_icon_; |
+ avatar_icon_ = NULL; |
+ } else if (show) { |
+ gfx::ImageSkia image = GetAvatarImageForContext( |
+ delegate->GetBrowserContextForWindow(window)).AsImageSkia(); |
+ DCHECK(!image.isNull()); |
+ if (!avatar_icon_) { |
+ avatar_icon_ = new views::ImageView(); |
+ AddChildView(avatar_icon_); |
+ } |
+ avatar_icon_->SetImage(image); |
+ avatar_icon_->SetBounds(0, 0, image.width(), image.height()); |
+ avatar_icon_->SchedulePaint(); |
+ } else { |
+ return; |
+ } |
+ header_painter_->UpdateAvatarIcon(avatar_icon_); |
+ Layout(); |
+} |
+ |
void CustomFrameViewAsh::HeaderView::Layout() { |
header_painter_->LayoutHeader(); |
header_painter_->set_header_height(GetPreferredHeight()); |
@@ -405,6 +448,7 @@ CustomFrameViewAsh::CustomFrameViewAsh(views::Widget* frame) |
new CustomFrameViewAshWindowStateDelegate( |
window_state, this))); |
} |
+ header_view_->UpdateAvatarIcon(); |
} |
CustomFrameViewAsh::~CustomFrameViewAsh() { |
@@ -504,10 +548,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: |