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

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: 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
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/frame_border_hit_test_controller.h" 11 #include "ash/frame/frame_border_hit_test_controller.h"
12 #include "ash/frame/frame_util.h"
12 #include "ash/frame/header_painter.h" 13 #include "ash/frame/header_painter.h"
14 #include "ash/session_state_delegate.h"
15 #include "ash/shell.h"
13 #include "ash/wm/immersive_fullscreen_controller.h" 16 #include "ash/wm/immersive_fullscreen_controller.h"
14 #include "ash/wm/window_state.h" 17 #include "ash/wm/window_state.h"
15 #include "ash/wm/window_state_delegate.h" 18 #include "ash/wm/window_state_delegate.h"
16 #include "ash/wm/window_state_observer.h" 19 #include "ash/wm/window_state_observer.h"
17 #include "base/command_line.h" 20 #include "base/command_line.h"
18 #include "base/debug/leak_annotations.h" 21 #include "base/debug/leak_annotations.h"
19 #include "grit/ash_resources.h" 22 #include "grit/ash_resources.h"
20 #include "ui/aura/client/aura_constants.h" 23 #include "ui/aura/client/aura_constants.h"
21 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
22 #include "ui/aura/window_observer.h" 25 #include "ui/aura/window_observer.h"
23 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
24 #include "ui/gfx/font_list.h" 27 #include "ui/gfx/font_list.h"
28 #include "ui/gfx/image/image.h"
25 #include "ui/gfx/rect.h" 29 #include "ui/gfx/rect.h"
26 #include "ui/gfx/rect_conversions.h" 30 #include "ui/gfx/rect_conversions.h"
27 #include "ui/gfx/size.h" 31 #include "ui/gfx/size.h"
32 #include "ui/views/controls/image_view.h"
28 #include "ui/views/view.h" 33 #include "ui/views/view.h"
29 #include "ui/views/widget/native_widget_aura.h" 34 #include "ui/views/widget/native_widget_aura.h"
30 #include "ui/views/widget/widget.h" 35 #include "ui/views/widget/widget.h"
31 #include "ui/views/widget/widget_delegate.h" 36 #include "ui/views/widget/widget_delegate.h"
32 #include "ui/views/widget/widget_deletion_observer.h" 37 #include "ui/views/widget/widget_deletion_observer.h"
33 38
34 namespace { 39 namespace {
35 40
36 const gfx::FontList& GetTitleFontList() { 41 const gfx::FontList& GetTitleFontList() {
37 static const gfx::FontList* title_font_list = 42 static const gfx::FontList* title_font_list =
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 154
150 // Returns the amount of the view's pixels which should be on screen. 155 // Returns the amount of the view's pixels which should be on screen.
151 int GetPreferredOnScreenHeight() const; 156 int GetPreferredOnScreenHeight() const;
152 157
153 // Returns the view's preferred height. 158 // Returns the view's preferred height.
154 int GetPreferredHeight() const; 159 int GetPreferredHeight() const;
155 160
156 // Returns the view's minimum width. 161 // Returns the view's minimum width.
157 int GetMinimumWidth() const; 162 int GetMinimumWidth() const;
158 163
164 // Updates the avatar icon based on the current state
165 // of the SessionStateDelegate::ShouldShowAvatar and
166 // SessionStateDelegate::GetUserImage.
167 void UpdateAvatarIcon();
168
159 // views::View overrides: 169 // views::View overrides:
160 virtual void Layout() OVERRIDE; 170 virtual void Layout() OVERRIDE;
161 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 171 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
162 172
163 HeaderPainter* header_painter() { 173 HeaderPainter* header_painter() {
164 return header_painter_.get(); 174 return header_painter_.get();
165 } 175 }
166 176
177 views::View* avatar_icon() const {
178 return avatar_icon_;
179 }
180
167 private: 181 private:
168 // ImmersiveFullscreenController::Delegate overrides: 182 // ImmersiveFullscreenController::Delegate overrides:
169 virtual void OnImmersiveRevealStarted() OVERRIDE; 183 virtual void OnImmersiveRevealStarted() OVERRIDE;
170 virtual void OnImmersiveRevealEnded() OVERRIDE; 184 virtual void OnImmersiveRevealEnded() OVERRIDE;
171 virtual void OnImmersiveFullscreenExited() OVERRIDE; 185 virtual void OnImmersiveFullscreenExited() OVERRIDE;
172 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; 186 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE;
173 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE; 187 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE;
174 188
175 // FrameMaximizeButtonObserver overrides: 189 // FrameMaximizeButtonObserver overrides:
176 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE; 190 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE;
177 191
178 // The widget that the caption buttons act on. 192 // The widget that the caption buttons act on.
179 views::Widget* frame_; 193 views::Widget* frame_;
180 194
195 views::ImageView* avatar_icon_;
196
181 // Helper for painting the header. 197 // Helper for painting the header.
182 scoped_ptr<HeaderPainter> header_painter_; 198 scoped_ptr<HeaderPainter> header_painter_;
183 199
184 // View which contains the window caption buttons. 200 // View which contains the window caption buttons.
185 FrameCaptionButtonContainerView* caption_button_container_; 201 FrameCaptionButtonContainerView* caption_button_container_;
186 202
187 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have 203 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have
188 // been already destroyed. 204 // been already destroyed.
189 views::Widget* maximize_bubble_; 205 views::Widget* maximize_bubble_;
190 206
191 // Keeps track of whether |maximize_bubble_| is still alive. 207 // Keeps track of whether |maximize_bubble_| is still alive.
192 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; 208 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_;
193 209
194 // The fraction of the header's height which is visible while in fullscreen. 210 // The fraction of the header's height which is visible while in fullscreen.
195 // This value is meaningless when not in fullscreen. 211 // This value is meaningless when not in fullscreen.
196 double fullscreen_visible_fraction_; 212 double fullscreen_visible_fraction_;
197 213
198 DISALLOW_COPY_AND_ASSIGN(HeaderView); 214 DISALLOW_COPY_AND_ASSIGN(HeaderView);
199 }; 215 };
200 216
201 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) 217 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
202 : frame_(frame), 218 : frame_(frame),
219 avatar_icon_(NULL),
203 header_painter_(new ash::HeaderPainter), 220 header_painter_(new ash::HeaderPainter),
204 caption_button_container_(NULL), 221 caption_button_container_(NULL),
205 maximize_bubble_(NULL), 222 maximize_bubble_(NULL),
206 fullscreen_visible_fraction_(0) { 223 fullscreen_visible_fraction_(0) {
207 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume 224 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume
208 // that the window frame can be minimized if it can be maximized. 225 // that the window frame can be minimized if it can be maximized.
209 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = 226 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed =
210 frame_->widget_delegate()->CanMaximize() ? 227 frame_->widget_delegate()->CanMaximize() ?
211 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : 228 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED :
212 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; 229 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { 265 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const {
249 // Reserve enough space to see the buttons and the separator line. 266 // Reserve enough space to see the buttons and the separator line.
250 return caption_button_container_->bounds().bottom() + 267 return caption_button_container_->bounds().bottom() +
251 header_painter_->HeaderContentSeparatorSize(); 268 header_painter_->HeaderContentSeparatorSize();
252 } 269 }
253 270
254 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { 271 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
255 return header_painter_->GetMinimumHeaderWidth(); 272 return header_painter_->GetMinimumHeaderWidth();
256 } 273 }
257 274
275 void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
276 SessionStateDelegate* delegate =
277 Shell::GetInstance()->session_state_delegate();
278 aura::Window* window = frame_->GetNativeView();
279 bool show = delegate->ShouldShowAvatar(window);
280 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.
281 delete avatar_icon_;
282 avatar_icon_ = NULL;
283 } else if (show) {
284 gfx::ImageSkia image = GetAvatarImageForContext(
285 delegate->GetBrowserContextForWindow(window)).AsImageSkia();
286 DCHECK(!image.isNull());
287 if (!avatar_icon_) {
288 avatar_icon_ = new views::ImageView();
289 AddChildView(avatar_icon_);
290 }
291 avatar_icon_->SetImage(image);
292 avatar_icon_->SetBounds(0, 0, image.width(), image.height());
293 avatar_icon_->SchedulePaint();
294 } else {
295 return;
296 }
297 header_painter_->UpdateAvatarIcon(avatar_icon_);
298 Layout();
299 }
300
258 void CustomFrameViewAsh::HeaderView::Layout() { 301 void CustomFrameViewAsh::HeaderView::Layout() {
259 header_painter_->LayoutHeader(); 302 header_painter_->LayoutHeader();
260 header_painter_->set_header_height(GetPreferredHeight()); 303 header_painter_->set_header_height(GetPreferredHeight());
261 } 304 }
262 305
263 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { 306 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) {
264 bool paint_as_active = 307 bool paint_as_active =
265 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); 308 frame_->non_client_view()->frame_view()->ShouldPaintAsActive();
266 caption_button_container_->SetPaintAsActive(paint_as_active); 309 caption_button_container_->SetPaintAsActive(paint_as_active);
267 310
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 frame->non_client_view()->SetOverlayView(new OverlayView(header_view_)); 441 frame->non_client_view()->SetOverlayView(new OverlayView(header_view_));
399 442
400 // A delegate for a more complex way of fullscreening the window may already 443 // A delegate for a more complex way of fullscreening the window may already
401 // be set. This is the case for packaged apps. 444 // be set. This is the case for packaged apps.
402 wm::WindowState* window_state = wm::GetWindowState(frame->GetNativeWindow()); 445 wm::WindowState* window_state = wm::GetWindowState(frame->GetNativeWindow());
403 if (!window_state->HasDelegate()) { 446 if (!window_state->HasDelegate()) {
404 window_state->SetDelegate(scoped_ptr<wm::WindowStateDelegate>( 447 window_state->SetDelegate(scoped_ptr<wm::WindowStateDelegate>(
405 new CustomFrameViewAshWindowStateDelegate( 448 new CustomFrameViewAshWindowStateDelegate(
406 window_state, this))); 449 window_state, this)));
407 } 450 }
451 header_view_->UpdateAvatarIcon();
408 } 452 }
409 453
410 CustomFrameViewAsh::~CustomFrameViewAsh() { 454 CustomFrameViewAsh::~CustomFrameViewAsh() {
411 } 455 }
412 456
413 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView( 457 void CustomFrameViewAsh::InitImmersiveFullscreenControllerForView(
414 ImmersiveFullscreenController* immersive_fullscreen_controller) { 458 ImmersiveFullscreenController* immersive_fullscreen_controller) {
415 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_); 459 immersive_fullscreen_controller->Init(header_view_, frame_, header_view_);
416 } 460 }
417 461
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 views::NonClientFrameView::SchedulePaintInRect(r); 541 views::NonClientFrameView::SchedulePaintInRect(r);
498 } 542 }
499 } 543 }
500 544
501 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { 545 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
502 // NonClientView hit tests the NonClientFrameView first instead of going in 546 // NonClientView hit tests the NonClientFrameView first instead of going in
503 // z-order. Return false so that events get to the OverlayView. 547 // z-order. Return false so that events get to the OverlayView.
504 return false; 548 return false;
505 } 549 }
506 550
551 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from,
552 bool is_visible) {
553 if (is_visible)
554 header_view_->UpdateAvatarIcon();
555 }
556
507 views::View* CustomFrameViewAsh::GetHeaderView() { 557 views::View* CustomFrameViewAsh::GetHeaderView() {
508 return header_view_; 558 return header_view_;
509 } 559 }
510 560
561 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
562 return header_view_->avatar_icon();
563 }
564
511 //////////////////////////////////////////////////////////////////////////////// 565 ////////////////////////////////////////////////////////////////////////////////
512 // CustomFrameViewAsh, private: 566 // CustomFrameViewAsh, private:
513 567
514 int CustomFrameViewAsh::NonClientTopBorderHeight() const { 568 int CustomFrameViewAsh::NonClientTopBorderHeight() const {
515 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); 569 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight();
516 } 570 }
517 571
518 } // namespace ash 572 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698