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

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/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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 144
140 // Returns the amount of the view's pixels which should be on screen. 145 // Returns the amount of the view's pixels which should be on screen.
141 int GetPreferredOnScreenHeight() const; 146 int GetPreferredOnScreenHeight() const;
142 147
143 // Returns the view's preferred height. 148 // Returns the view's preferred height.
144 int GetPreferredHeight() const; 149 int GetPreferredHeight() const;
145 150
146 // Returns the view's minimum width. 151 // Returns the view's minimum width.
147 int GetMinimumWidth() const; 152 int GetMinimumWidth() const;
148 153
154 void UpdateAvatarIcon();
155
149 // views::View overrides: 156 // views::View overrides:
150 virtual void Layout() OVERRIDE; 157 virtual void Layout() OVERRIDE;
151 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; 158 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
152 159
153 FrameCaptionButtonContainerView* caption_button_container() { 160 FrameCaptionButtonContainerView* caption_button_container() {
154 return caption_button_container_; 161 return caption_button_container_;
155 } 162 }
156 163
164 views::View* avatar_icon() const {
165 return avatar_icon_;
166 }
167
157 private: 168 private:
158 // ImmersiveFullscreenController::Delegate overrides: 169 // ImmersiveFullscreenController::Delegate overrides:
159 virtual void OnImmersiveRevealStarted() OVERRIDE; 170 virtual void OnImmersiveRevealStarted() OVERRIDE;
160 virtual void OnImmersiveRevealEnded() OVERRIDE; 171 virtual void OnImmersiveRevealEnded() OVERRIDE;
161 virtual void OnImmersiveFullscreenExited() OVERRIDE; 172 virtual void OnImmersiveFullscreenExited() OVERRIDE;
162 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE; 173 virtual void SetVisibleFraction(double visible_fraction) OVERRIDE;
163 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE; 174 virtual std::vector<gfx::Rect> GetVisibleBoundsInScreen() const OVERRIDE;
164 175
165 // FrameMaximizeButtonObserver overrides: 176 // FrameMaximizeButtonObserver overrides:
166 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE; 177 virtual void OnMaximizeBubbleShown(views::Widget* bubble) OVERRIDE;
167 178
168 // The widget that the caption buttons act on. 179 // The widget that the caption buttons act on.
169 views::Widget* frame_; 180 views::Widget* frame_;
170 181
171 // Helper for painting the header. 182 // Helper for painting the header.
172 scoped_ptr<DefaultHeaderPainter> header_painter_; 183 scoped_ptr<DefaultHeaderPainter> header_painter_;
173 184
185 views::ImageView* avatar_icon_;
186
174 // View which contains the window caption buttons. 187 // View which contains the window caption buttons.
175 FrameCaptionButtonContainerView* caption_button_container_; 188 FrameCaptionButtonContainerView* caption_button_container_;
176 189
177 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have 190 // The maximize bubble widget. |maximize_bubble_| may be non-NULL but have
178 // been already destroyed. 191 // been already destroyed.
179 views::Widget* maximize_bubble_; 192 views::Widget* maximize_bubble_;
180 193
181 // Keeps track of whether |maximize_bubble_| is still alive. 194 // Keeps track of whether |maximize_bubble_| is still alive.
182 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_; 195 scoped_ptr<views::WidgetDeletionObserver> maximize_bubble_lifetime_observer_;
183 196
184 // The fraction of the header's height which is visible while in fullscreen. 197 // The fraction of the header's height which is visible while in fullscreen.
185 // This value is meaningless when not in fullscreen. 198 // This value is meaningless when not in fullscreen.
186 double fullscreen_visible_fraction_; 199 double fullscreen_visible_fraction_;
187 200
188 DISALLOW_COPY_AND_ASSIGN(HeaderView); 201 DISALLOW_COPY_AND_ASSIGN(HeaderView);
189 }; 202 };
190 203
191 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame) 204 CustomFrameViewAsh::HeaderView::HeaderView(views::Widget* frame)
192 : frame_(frame), 205 : frame_(frame),
193 header_painter_(new ash::DefaultHeaderPainter), 206 header_painter_(new ash::DefaultHeaderPainter),
207 avatar_icon_(NULL),
194 caption_button_container_(NULL), 208 caption_button_container_(NULL),
195 maximize_bubble_(NULL), 209 maximize_bubble_(NULL),
196 fullscreen_visible_fraction_(0) { 210 fullscreen_visible_fraction_(0) {
197 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume 211 // Unfortunately, there is no views::WidgetDelegate::CanMinimize(). Assume
198 // that the window frame can be minimized if it can be maximized. 212 // that the window frame can be minimized if it can be maximized.
199 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed = 213 FrameCaptionButtonContainerView::MinimizeAllowed minimize_allowed =
200 frame_->widget_delegate()->CanMaximize() ? 214 frame_->widget_delegate()->CanMaximize() ?
201 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED : 215 FrameCaptionButtonContainerView::MINIMIZE_ALLOWED :
202 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED; 216 FrameCaptionButtonContainerView::MINIMIZE_DISALLOWED;
203 caption_button_container_ = new FrameCaptionButtonContainerView(frame_, 217 caption_button_container_ = new FrameCaptionButtonContainerView(frame_,
204 minimize_allowed); 218 minimize_allowed);
205 AddChildView(caption_button_container_); 219 AddChildView(caption_button_container_);
206 FrameMaximizeButton* frame_maximize_button = 220 FrameMaximizeButton* frame_maximize_button =
207 caption_button_container_->GetOldStyleSizeButton(); 221 caption_button_container_->GetOldStyleSizeButton();
208 if (frame_maximize_button) 222 if (frame_maximize_button)
209 frame_maximize_button->AddObserver(this); 223 frame_maximize_button->AddObserver(this);
210 224
211 header_painter_->Init(frame_, this, NULL, caption_button_container_); 225 header_painter_->Init(frame_, this, NULL, caption_button_container_);
226 UpdateAvatarIcon();
212 } 227 }
213 228
214 CustomFrameViewAsh::HeaderView::~HeaderView() { 229 CustomFrameViewAsh::HeaderView::~HeaderView() {
215 FrameMaximizeButton* frame_maximize_button = 230 FrameMaximizeButton* frame_maximize_button =
216 caption_button_container_->GetOldStyleSizeButton(); 231 caption_button_container_->GetOldStyleSizeButton();
217 if (frame_maximize_button) 232 if (frame_maximize_button)
218 frame_maximize_button->RemoveObserver(this); 233 frame_maximize_button->RemoveObserver(this);
219 } 234 }
220 235
221 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() { 236 void CustomFrameViewAsh::HeaderView::SchedulePaintForTitle() {
(...skipping 13 matching lines...) Expand all
235 } 250 }
236 251
237 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const { 252 int CustomFrameViewAsh::HeaderView::GetPreferredHeight() const {
238 return header_painter_->GetHeaderHeightForPainting(); 253 return header_painter_->GetHeaderHeightForPainting();
239 } 254 }
240 255
241 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const { 256 int CustomFrameViewAsh::HeaderView::GetMinimumWidth() const {
242 return header_painter_->GetMinimumHeaderWidth(); 257 return header_painter_->GetMinimumHeaderWidth();
243 } 258 }
244 259
260 void CustomFrameViewAsh::HeaderView::UpdateAvatarIcon() {
261 SessionStateDelegate* delegate =
262 Shell::GetInstance()->session_state_delegate();
263 aura::Window* window = frame_->GetNativeView();
264 bool show = delegate->ShouldShowAvatar(window);
265 int icon_size = 0;
266 if (!show) {
267 if (!avatar_icon_)
268 return;
269 delete avatar_icon_;
270 avatar_icon_ = NULL;
271 } else {
272 gfx::ImageSkia image = GetAvatarImageForContext(
273 delegate->GetBrowserContextForWindow(window)).AsImageSkia();
274 DCHECK(!image.isNull());
275 DCHECK_EQ(image.width(), image.height());
276 if (!avatar_icon_) {
277 avatar_icon_ = new views::ImageView();
278 AddChildView(avatar_icon_);
279 }
280 avatar_icon_->SetImage(image);
281 icon_size = image.width();
282 }
283 header_painter_->UpdateWindowIcon(avatar_icon_, icon_size);
284 Layout();
285 }
286
245 void CustomFrameViewAsh::HeaderView::Layout() { 287 void CustomFrameViewAsh::HeaderView::Layout() {
246 header_painter_->LayoutHeader(); 288 header_painter_->LayoutHeader();
247 } 289 }
248 290
249 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) { 291 void CustomFrameViewAsh::HeaderView::OnPaint(gfx::Canvas* canvas) {
250 bool paint_as_active = 292 bool paint_as_active =
251 frame_->non_client_view()->frame_view()->ShouldPaintAsActive(); 293 frame_->non_client_view()->frame_view()->ShouldPaintAsActive();
252 caption_button_container_->SetPaintAsActive(paint_as_active); 294 caption_button_container_->SetPaintAsActive(paint_as_active);
253 295
254 HeaderPainter::Mode header_mode = paint_as_active ? 296 HeaderPainter::Mode header_mode = paint_as_active ?
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 views::NonClientFrameView::SchedulePaintInRect(r); 514 views::NonClientFrameView::SchedulePaintInRect(r);
473 } 515 }
474 } 516 }
475 517
476 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const { 518 bool CustomFrameViewAsh::HitTestRect(const gfx::Rect& rect) const {
477 // NonClientView hit tests the NonClientFrameView first instead of going in 519 // NonClientView hit tests the NonClientFrameView first instead of going in
478 // z-order. Return false so that events get to the OverlayView. 520 // z-order. Return false so that events get to the OverlayView.
479 return false; 521 return false;
480 } 522 }
481 523
524 void CustomFrameViewAsh::VisibilityChanged(views::View* starting_from,
525 bool is_visible) {
526 if (is_visible)
527 header_view_->UpdateAvatarIcon();
528 }
529
482 views::View* CustomFrameViewAsh::GetHeaderView() { 530 views::View* CustomFrameViewAsh::GetHeaderView() {
483 return header_view_; 531 return header_view_;
484 } 532 }
485 533
534 const views::View* CustomFrameViewAsh::GetAvatarIconViewForTest() const {
535 return header_view_->avatar_icon();
536 }
537
486 //////////////////////////////////////////////////////////////////////////////// 538 ////////////////////////////////////////////////////////////////////////////////
487 // CustomFrameViewAsh, private: 539 // CustomFrameViewAsh, private:
488 540
489 int CustomFrameViewAsh::NonClientTopBorderHeight() const { 541 int CustomFrameViewAsh::NonClientTopBorderHeight() const {
490 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight(); 542 return frame_->IsFullscreen() ? 0 : header_view_->GetPreferredHeight();
491 } 543 }
492 544
493 } // namespace ash 545 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698