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

Side by Side 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: rebase 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/frame/custom_frame_view_ash.h ('k') | ash/frame/custom_frame_view_ash_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/frame/custom_frame_view_ash.h" 5 #include "ash/frame/custom_frame_view_ash.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 8 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
9 #include "ash/frame/caption_buttons/frame_maximize_button.h" 9 #include "ash/frame/caption_buttons/frame_maximize_button.h"
10 #include "ash/frame/caption_buttons/frame_maximize_button_observer.h" 10 #include "ash/frame/caption_buttons/frame_maximize_button_observer.h"
11 #include "ash/frame/default_header_painter.h" 11 #include "ash/frame/default_header_painter.h"
12 #include "ash/frame/frame_border_hit_test_controller.h" 12 #include "ash/frame/frame_border_hit_test_controller.h"
13 #include "ash/frame/frame_util.h"
13 #include "ash/frame/header_painter.h" 14 #include "ash/frame/header_painter.h"
15 #include "ash/session_state_delegate.h"
16 #include "ash/shell.h"
14 #include "ash/wm/immersive_fullscreen_controller.h" 17 #include "ash/wm/immersive_fullscreen_controller.h"
15 #include "ash/wm/window_state.h" 18 #include "ash/wm/window_state.h"
16 #include "ash/wm/window_state_delegate.h" 19 #include "ash/wm/window_state_delegate.h"
17 #include "ash/wm/window_state_observer.h" 20 #include "ash/wm/window_state_observer.h"
18 #include "base/command_line.h" 21 #include "base/command_line.h"
19 #include "ui/aura/client/aura_constants.h" 22 #include "ui/aura/client/aura_constants.h"
20 #include "ui/aura/window.h" 23 #include "ui/aura/window.h"
21 #include "ui/aura/window_observer.h" 24 #include "ui/aura/window_observer.h"
22 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/image/image.h"
23 #include "ui/gfx/rect.h" 27 #include "ui/gfx/rect.h"
24 #include "ui/gfx/rect_conversions.h" 28 #include "ui/gfx/rect_conversions.h"
25 #include "ui/gfx/size.h" 29 #include "ui/gfx/size.h"
30 #include "ui/views/controls/image_view.h"
26 #include "ui/views/view.h" 31 #include "ui/views/view.h"
27 #include "ui/views/widget/widget.h" 32 #include "ui/views/widget/widget.h"
28 #include "ui/views/widget/widget_delegate.h" 33 #include "ui/views/widget/widget_delegate.h"
29 #include "ui/views/widget/widget_deletion_observer.h" 34 #include "ui/views/widget/widget_deletion_observer.h"
30 35
31 namespace { 36 namespace {
32 37
33 /////////////////////////////////////////////////////////////////////////////// 38 ///////////////////////////////////////////////////////////////////////////////
34 // CustomFrameViewAshWindowStateDelegate 39 // CustomFrameViewAshWindowStateDelegate
35 40
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 140
136 // Returns the amount of the view's pixels which should be on screen. 141 // Returns the amount of the view's pixels which should be on screen.
137 int GetPreferredOnScreenHeight() const; 142 int GetPreferredOnScreenHeight() const;
138 143
139 // Returns the view's preferred height. 144 // Returns the view's preferred height.
140 int GetPreferredHeight() const; 145 int GetPreferredHeight() const;
141 146
142 // Returns the view's minimum width. 147 // Returns the view's minimum width.
143 int GetMinimumWidth() const; 148 int GetMinimumWidth() const;
144 149
150 void UpdateAvatarIcon();
151
145 // views::View overrides: 152 // views::View overrides:
146 virtual void Layout() OVERRIDE; 153 virtual void Layout() OVERRIDE;
147 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 154 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
148 155
149 FrameCaptionButtonContainerView* caption_button_container() { 156 FrameCaptionButtonContainerView* caption_button_container() {
150 return caption_button_container_; 157 return caption_button_container_;
151 } 158 }
152 159
160 views::View* avatar_icon() const {
161 return avatar_icon_;
162 }
163
153 private: 164 private:
154 // ImmersiveFullscreenController::Delegate overrides: 165 // ImmersiveFullscreenController::Delegate overrides:
155 virtual void OnImmersiveRevealStarted() OVERRIDE; 166 virtual void OnImmersiveRevealStarted() OVERRIDE;
156 virtual void OnImmersiveRevealEnded() OVERRIDE; 167 virtual void OnImmersiveRevealEnded() OVERRIDE;
157 virtual void OnImmersiveFullscreenExited() OVERRIDE; 168 virtual void OnImmersiveFullscreenExited() OVERRIDE;
158 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; 169 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE;
159 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE; 170 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE;
160 171
161 // FrameMaximizeButtonObserver overrides: 172 // FrameMaximizeButtonObserver overrides:
162 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE; 173 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE;
163 174
164 // The widget that the caption buttons act on. 175 // The widget that the caption buttons act on.
165 views::Widget* frame_; 176 views::Widget* frame_;
166 177
167 // Helper for painting the header. 178 // Helper for painting the header.
168 scoped_ptr<DefaultHeaderPainter> header_painter_; 179 scoped_ptr<DefaultHeaderPainter> header_painter_;
169 180
181 views::ImageView* avatar_icon_;
182
170 // View which contains the window caption buttons. 183 // View which contains the window caption buttons.
171 FrameCaptionButtonContainerView* caption_button_container_; 184 FrameCaptionButtonContainerView* caption_button_container_;
172 185
173 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have 186 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have
174 // been already destroyed. 187 // been already destroyed.
175 views::Widget* maximize_bubble_; 188 views::Widget* maximize_bubble_;
176 189
177 // Keeps track of whether |maximize_bubble_| is still alive. 190 // Keeps track of whether |maximize_bubble_| is still alive.
178 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; 191 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_;
179 192
180 // The fraction of the header's height which is visible while in fullscreen. 193 // The fraction of the header's height which is visible while in fullscreen.
181 // This value is meaningless when not in fullscreen. 194 // This value is meaningless when not in fullscreen.
182 double fullscreen_visible_fraction_; 195 double fullscreen_visible_fraction_;
183 196
184 DISALLOW_COPY_AND_ASSIGN(HeaderView); 197 DISALLOW_COPY_AND_ASSIGN(HeaderView);
185 }; 198 };
186 199
187 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) 200 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
188 : frame_(frame), 201 : frame_(frame),
189 header_painter_(new ash::DefaultHeaderPainter), 202 header_painter_(new ash::DefaultHeaderPainter),
203 avatar_icon_(NULL),
190 caption_button_container_(NULL), 204 caption_button_container_(NULL),
191 maximize_bubble_(NULL), 205 maximize_bubble_(NULL),
192 fullscreen_visible_fraction_(0) { 206 fullscreen_visible_fraction_(0) {
193 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume 207 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume
194 // that the window frame can be minimized if it can be maximized. 208 // that the window frame can be minimized if it can be maximized.
195 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = 209 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed =
196 frame_->widget_delegate()->CanMaximize() ? 210 frame_->widget_delegate()->CanMaximize() ?
197 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : 211 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED :
198 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; 212 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED;
199 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, 213 caption_button_container_ = new FrameCaptionButtonContainerView(frame_,
200 minimize_allowed); 214 minimize_allowed);
201 AddChildView(caption_button_container_); 215 AddChildView(caption_button_container_);
202 FrameMaximizeButton* frame_maximize_button = 216 FrameMaximizeButton* frame_maximize_button =
203 caption_button_container_->GetOldStyleSizeButton(); 217 caption_button_container_->GetOldStyleSizeButton();
204 if (frame_maximize_button) 218 if (frame_maximize_button)
205 frame_maximize_button->AddObserver(this); 219 frame_maximize_button->AddObserver(this);
206 220
207 header_painter_->Init(frame_, this, NULL, caption_button_container_); 221 header_painter_->Init(frame_, this, NULL, caption_button_container_);
222 UpdateAvatarIcon();
208 } 223 }
209 224
210 CustomFrameViewAsh::HeaderView::~HeaderView() { 225 CustomFrameViewAsh::HeaderView::~HeaderView() {
211 FrameMaximizeButton* frame_maximize_button = 226 FrameMaximizeButton* frame_maximize_button =
212 caption_button_container_->GetOldStyleSizeButton(); 227 caption_button_container_->GetOldStyleSizeButton();
213 if (frame_maximize_button) 228 if (frame_maximize_button)
214 frame_maximize_button->RemoveObserver(this); 229 frame_maximize_button->RemoveObserver(this);
215 } 230 }
216 231
217 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { 232 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() {
(...skipping 13 matching lines...) Expand all
231 } 246 }
232 247
233 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { 248 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const {
234 return header_painter_->GetHeaderHeightForPainting(); 249 return header_painter_->GetHeaderHeightForPainting();
235 } 250 }
236 251
237 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { 252 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
238 return header_painter_->GetMinimumHeaderWidth(); 253 return header_painter_->GetMinimumHeaderWidth();
239 } 254 }
240 255
256 void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
257 SessionStateDelegate* delegate =
258 Shell::GetInstance()->session_state_delegate();
259 aura::Window* window = frame_->GetNativeView();
260 bool show = delegate->ShouldShowAvatar(window);
261 int icon_size = 0;
262 if (!show) {
263 if (!avatar_icon_)
264 return;
265 delete avatar_icon_;
266 avatar_icon_ = NULL;
267 } else {
268 gfx::ImageSkia image = GetAvatarImageForContext(
269 delegate->GetBrowserContextForWindow(window)).AsImageSkia();
270 DCHECK(!image.isNull());
271 DCHECK_EQ(image.width(), image.height());
272 if (!avatar_icon_) {
273 avatar_icon_ = new views::ImageView();
274 AddChildView(avatar_icon_);
275 }
276 avatar_icon_->SetImage(image);
277 icon_size = image.width();
278 }
279 header_painter_->UpdateWindowIcon(avatar_icon_, icon_size);
280 Layout();
281 }
282
241 void CustomFrameViewAsh::HeaderView::Layout() { 283 void CustomFrameViewAsh::HeaderView::Layout() {
242 header_painter_->LayoutHeader(); 284 header_painter_->LayoutHeader();
243 } 285 }
244 286
245 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { 287 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) {
246 bool paint_as_active = 288 bool paint_as_active =
247 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); 289 frame_->non_client_view()->frame_view()->ShouldPaintAsActive();
248 caption_button_container_->SetPaintAsActive(paint_as_active); 290 caption_button_container_->SetPaintAsActive(paint_as_active);
249 291
250 HeaderPainter::Mode header_mode = paint_as_active ? 292 HeaderPainter::Mode header_mode = paint_as_active ?
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 views::NonClientFrameView::SchedulePaintInRect(r); 510 views::NonClientFrameView::SchedulePaintInRect(r);
469 } 511 }
470 } 512 }
471 513
472 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { 514 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
473 // NonClientView hit tests the NonClientFrameView first instead of going in 515 // NonClientView hit tests the NonClientFrameView first instead of going in
474 // z-order. Return false so that events get to the OverlayView. 516 // z-order. Return false so that events get to the OverlayView.
475 return false; 517 return false;
476 } 518 }
477 519
520 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from,
521 bool is_visible) {
522 if (is_visible)
523 header_view_->UpdateAvatarIcon();
524 }
525
478 views::View* CustomFrameViewAsh::GetHeaderView() { 526 views::View* CustomFrameViewAsh::GetHeaderView() {
479 return header_view_; 527 return header_view_;
480 } 528 }
481 529
530 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
531 return header_view_->avatar_icon();
532 }
533
482 //////////////////////////////////////////////////////////////////////////////// 534 ////////////////////////////////////////////////////////////////////////////////
483 // CustomFrameViewAsh, private: 535 // CustomFrameViewAsh, private:
484 536
485 int CustomFrameViewAsh::NonClientTopBorderHeight() const { 537 int CustomFrameViewAsh::NonClientTopBorderHeight() const {
486 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); 538 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight();
487 } 539 }
488 540
489 } // namespace ash 541 } // namespace ash
OLDNEW
« no previous file with comments | « ash/frame/custom_frame_view_ash.h ('k') | ash/frame/custom_frame_view_ash_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698