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

Side by Side Diff: ash/frame/header_painter.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/header_painter.h" 5 #include "ash/frame/header_painter.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 9 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
10 #include "base/logging.h" // DCHECK 10 #include "base/logging.h" // DCHECK
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 136
137 namespace ash { 137 namespace ash {
138 138
139 /////////////////////////////////////////////////////////////////////////////// 139 ///////////////////////////////////////////////////////////////////////////////
140 // HeaderPainter, public: 140 // HeaderPainter, public:
141 141
142 HeaderPainter::HeaderPainter() 142 HeaderPainter::HeaderPainter()
143 : frame_(NULL), 143 : frame_(NULL),
144 header_view_(NULL), 144 header_view_(NULL),
145 window_icon_(NULL), 145 window_icon_(NULL),
146 avatar_icon_(NULL),
146 caption_button_container_(NULL), 147 caption_button_container_(NULL),
147 header_height_(0), 148 header_height_(0),
148 previous_theme_frame_id_(0), 149 previous_theme_frame_id_(0),
149 previous_theme_frame_overlay_id_(0), 150 previous_theme_frame_overlay_id_(0),
150 crossfade_theme_frame_id_(0), 151 crossfade_theme_frame_id_(0),
151 crossfade_theme_frame_overlay_id_(0) {} 152 crossfade_theme_frame_overlay_id_(0) {}
152 153
153 HeaderPainter::~HeaderPainter() { 154 HeaderPainter::~HeaderPainter() {
154 } 155 }
155 156
156 void HeaderPainter::Init( 157 void HeaderPainter::Init(
157 Style style, 158 Style style,
158 views::Widget* frame, 159 views::Widget* frame,
159 views::View* header_view, 160 views::View* header_view,
160 views::View* window_icon, 161 views::View* window_icon,
161 FrameCaptionButtonContainerView* caption_button_container) { 162 FrameCaptionButtonContainerView* caption_button_container) {
162 DCHECK(frame); 163 DCHECK(frame);
163 DCHECK(header_view); 164 DCHECK(header_view);
164 // window_icon may be NULL. 165 // window_icon may be NULL.
165 DCHECK(caption_button_container); 166 DCHECK(caption_button_container);
166 style_ = style; 167 style_ = style;
167 frame_ = frame; 168 frame_ = frame;
168 header_view_ = header_view; 169 header_view_ = header_view;
169 window_icon_ = window_icon; 170 window_icon_ = window_icon;
170 caption_button_container_ = caption_button_container; 171 caption_button_container_ = caption_button_container;
171 } 172 }
172 173
174 void HeaderPainter::UpdateAvatarIcon(views::View* avatar_icon) {
175 avatar_icon_ = avatar_icon;
176 }
177
173 // static 178 // static
174 gfx::Rect HeaderPainter::GetBoundsForClientView( 179 gfx::Rect HeaderPainter::GetBoundsForClientView(
175 int header_height, 180 int header_height,
176 const gfx::Rect& window_bounds) { 181 const gfx::Rect& window_bounds) {
177 gfx::Rect client_bounds(window_bounds); 182 gfx::Rect client_bounds(window_bounds);
178 client_bounds.Inset(0, header_height, 0, 0); 183 client_bounds.Inset(0, header_height, 0, 0);
179 return client_bounds; 184 return client_bounds;
180 } 185 }
181 186
182 // static 187 // static
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 caption_button_container_->Layout(); 361 caption_button_container_->Layout();
357 362
358 gfx::Size caption_button_container_size = 363 gfx::Size caption_button_container_size =
359 caption_button_container_->GetPreferredSize(); 364 caption_button_container_->GetPreferredSize();
360 caption_button_container_->SetBounds( 365 caption_button_container_->SetBounds(
361 header_view_->width() - caption_button_container_size.width(), 366 header_view_->width() - caption_button_container_size.width(),
362 0, 367 0,
363 caption_button_container_size.width(), 368 caption_button_container_size.width(),
364 caption_button_container_size.height()); 369 caption_button_container_size.height());
365 370
371 if (avatar_icon_) {
372 int icon_offset_y =
373 GetCaptionButtonContainerCenterY() - avatar_icon_->height() / 2;
374 avatar_icon_->SetBounds(kIconOffsetX, icon_offset_y,
375 avatar_icon_->width(), avatar_icon_->height());
376 }
377
366 if (window_icon_) { 378 if (window_icon_) {
367 // Vertically center the window icon with respect to the caption button 379 // Vertically center the window icon with respect to the caption button
368 // container. 380 // container.
369 int icon_offset_y = 381 int icon_offset_y =
370 GetCaptionButtonContainerCenterY() - window_icon_->height() / 2; 382 GetCaptionButtonContainerCenterY() - window_icon_->height() / 2;
371 window_icon_->SetBounds(kIconOffsetX, icon_offset_y, kIconSize, kIconSize); 383 window_icon_->SetBounds(GetWindowIconOffsetX(), icon_offset_y,
384 kIconSize, kIconSize);
372 } 385 }
373 } 386 }
374 387
375 void HeaderPainter::SchedulePaintForTitle( 388 void HeaderPainter::SchedulePaintForTitle(
376 const gfx::FontList& title_font_list) { 389 const gfx::FontList& title_font_list) {
377 header_view_->SchedulePaintInRect(GetTitleBounds(title_font_list)); 390 header_view_->SchedulePaintInRect(GetTitleBounds(title_font_list));
378 } 391 }
379 392
380 void HeaderPainter::OnThemeChanged() { 393 void HeaderPainter::OnThemeChanged() {
381 // We do not cache the images for |previous_theme_frame_id_| and 394 // We do not cache the images for |previous_theme_frame_id_| and
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, 598 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
586 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); 599 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
587 } 600 }
588 } 601 }
589 602
590 gfx::Rect HeaderPainter::GetHeaderLocalBounds() const { 603 gfx::Rect HeaderPainter::GetHeaderLocalBounds() const {
591 return gfx::Rect(header_view_->width(), header_height_); 604 return gfx::Rect(header_view_->width(), header_height_);
592 } 605 }
593 606
594 int HeaderPainter::GetTitleOffsetX() const { 607 int HeaderPainter::GetTitleOffsetX() const {
595 return window_icon_ ? 608 views::View* left = window_icon_ ? window_icon_ : avatar_icon_;
596 window_icon_->bounds().right() + kTitleIconOffsetX : 609 return left ? left->bounds().right() + kTitleIconOffsetX :
597 kTitleNoIconOffsetX; 610 kTitleNoIconOffsetX;
598 } 611 }
599 612
613 int HeaderPainter::GetWindowIconOffsetX() const {
614 return avatar_icon_ ?
615 avatar_icon_->bounds().right() + kIconOffsetX : kIconOffsetX;
616 }
617
600 int HeaderPainter::GetCaptionButtonContainerCenterY() const { 618 int HeaderPainter::GetCaptionButtonContainerCenterY() const {
601 return caption_button_container_->y() + 619 return caption_button_container_->y() +
602 caption_button_container_->height() / 2; 620 caption_button_container_->height() / 2;
603 } 621 }
604 622
605 int HeaderPainter::GetHeaderCornerRadius() const { 623 int HeaderPainter::GetHeaderCornerRadius() const {
606 bool square_corners = (frame_->IsMaximized() || frame_->IsFullscreen()); 624 bool square_corners = (frame_->IsMaximized() || frame_->IsFullscreen());
607 const int kCornerRadius = 2; 625 const int kCornerRadius = 2;
608 return square_corners ? 0 : kCornerRadius; 626 return square_corners ? 0 : kCornerRadius;
609 } 627 }
610 628
611 gfx::Rect HeaderPainter::GetTitleBounds(const gfx::FontList& title_font_list) { 629 gfx::Rect HeaderPainter::GetTitleBounds(const gfx::FontList& title_font_list) {
612 int title_x = GetTitleOffsetX(); 630 int title_x = GetTitleOffsetX();
613 // Center the text with respect to the caption button container. This way it 631 // Center the text with respect to the caption button container. This way it
614 // adapts to the caption button height and aligns exactly with the window 632 // adapts to the caption button height and aligns exactly with the window
615 // icon. Don't use |window_icon_| for this computation as it may be NULL. 633 // icon. Don't use |window_icon_| for this computation as it may be NULL.
616 int title_y = 634 int title_y =
617 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2; 635 GetCaptionButtonContainerCenterY() - title_font_list.GetHeight() / 2;
618 return gfx::Rect( 636 return gfx::Rect(
619 title_x, 637 title_x,
620 std::max(0, title_y), 638 std::max(0, title_y),
621 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x), 639 std::max(0, caption_button_container_->x() - kTitleLogoSpacing - title_x),
622 title_font_list.GetHeight()); 640 title_font_list.GetHeight());
623 } 641 }
624 642
625 } // namespace ash 643 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698