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

Side by Side Diff: ash/frame/default_header_painter.cc

Issue 441803004: Introduce new WebApp header style for hosted apps and fizzy apps on ash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Real assets, crushed, review feedback Created 6 years, 4 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/default_header_painter.h" 5 #include "ash/frame/default_header_painter.h"
6 6
7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h" 7 #include "ash/frame/caption_buttons/frame_caption_button_container_view.h"
8 #include "ash/frame/header_painter_util.h" 8 #include "ash/frame/header_painter_util.h"
9 #include "base/debug/leak_annotations.h" 9 #include "base/debug/leak_annotations.h"
10 #include "base/logging.h" // DCHECK 10 #include "base/logging.h" // DCHECK
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } // namespace 67 } // namespace
68 68
69 namespace ash { 69 namespace ash {
70 70
71 /////////////////////////////////////////////////////////////////////////////// 71 ///////////////////////////////////////////////////////////////////////////////
72 // DefaultHeaderPainter, public: 72 // DefaultHeaderPainter, public:
73 73
74 DefaultHeaderPainter::DefaultHeaderPainter() 74 DefaultHeaderPainter::DefaultHeaderPainter()
75 : frame_(NULL), 75 : frame_(NULL),
76 view_(NULL), 76 view_(NULL),
77 window_icon_(NULL), 77 left_header_view_(NULL),
78 window_icon_size_(HeaderPainterUtil::GetDefaultIconSize()), 78 left_view_x_inset_(HeaderPainterUtil::GetDefaultLeftViewXInset()),
79 caption_button_container_(NULL), 79 caption_button_container_(NULL),
80 height_(0), 80 height_(0),
81 mode_(MODE_INACTIVE), 81 mode_(MODE_INACTIVE),
82 initial_paint_(true), 82 initial_paint_(true),
83 activation_animation_(new gfx::SlideAnimation(this)) { 83 activation_animation_(new gfx::SlideAnimation(this)) {
84 } 84 }
85 85
86 DefaultHeaderPainter::~DefaultHeaderPainter() { 86 DefaultHeaderPainter::~DefaultHeaderPainter() {
87 } 87 }
88 88
89 void DefaultHeaderPainter::Init( 89 void DefaultHeaderPainter::Init(
90 views::Widget* frame, 90 views::Widget* frame,
91 views::View* header_view, 91 views::View* header_view,
92 views::View* window_icon,
93 FrameCaptionButtonContainerView* caption_button_container) { 92 FrameCaptionButtonContainerView* caption_button_container) {
94 DCHECK(frame); 93 DCHECK(frame);
95 DCHECK(header_view); 94 DCHECK(header_view);
96 // window_icon may be NULL.
97 DCHECK(caption_button_container); 95 DCHECK(caption_button_container);
98 frame_ = frame; 96 frame_ = frame;
99 view_ = header_view; 97 view_ = header_view;
100 window_icon_ = window_icon;
101 caption_button_container_ = caption_button_container; 98 caption_button_container_ = caption_button_container;
102 99
103 caption_button_container_->SetButtonImages( 100 caption_button_container_->SetButtonImages(
104 CAPTION_BUTTON_ICON_MINIMIZE, 101 CAPTION_BUTTON_ICON_MINIMIZE,
105 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, 102 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE,
106 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, 103 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I,
107 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, 104 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H,
108 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); 105 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P);
109 caption_button_container_->SetButtonImages( 106 caption_button_container_->SetButtonImages(
110 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, 107 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 caption_button_container_->Layout(); 200 caption_button_container_->Layout();
204 201
205 gfx::Size caption_button_container_size = 202 gfx::Size caption_button_container_size =
206 caption_button_container_->GetPreferredSize(); 203 caption_button_container_->GetPreferredSize();
207 caption_button_container_->SetBounds( 204 caption_button_container_->SetBounds(
208 view_->width() - caption_button_container_size.width(), 205 view_->width() - caption_button_container_size.width(),
209 0, 206 0,
210 caption_button_container_size.width(), 207 caption_button_container_size.width(),
211 caption_button_container_size.height()); 208 caption_button_container_size.height());
212 209
213 if (window_icon_) { 210 LayoutLeftHeaderView();
214 // Vertically center the window icon with respect to the caption button
215 // container.
216 // Floor when computing the center of |caption_button_container_|.
217 int icon_offset_y =
218 caption_button_container_->height() / 2 - window_icon_size_ / 2;
219 window_icon_->SetBounds(HeaderPainterUtil::GetIconXOffset(), icon_offset_y,
220 window_icon_size_, window_icon_size_);
221 }
222 211
223 // The header/content separator line overlays the caption buttons. 212 // The header/content separator line overlays the caption buttons.
224 SetHeaderHeightForPainting(caption_button_container_->height()); 213 SetHeaderHeightForPainting(caption_button_container_->height());
225 } 214 }
226 215
227 int DefaultHeaderPainter::GetHeaderHeightForPainting() const { 216 int DefaultHeaderPainter::GetHeaderHeightForPainting() const {
228 return height_; 217 return height_;
229 } 218 }
230 219
231 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) { 220 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) {
232 height_ = height; 221 height_ = height;
233 } 222 }
234 223
235 void DefaultHeaderPainter::SchedulePaintForTitle() { 224 void DefaultHeaderPainter::SchedulePaintForTitle() {
236 view_->SchedulePaintInRect(GetTitleBounds()); 225 view_->SchedulePaintInRect(GetTitleBounds());
237 } 226 }
238 227
239 void DefaultHeaderPainter::UpdateWindowIcon(views::View* window_icon, 228 void DefaultHeaderPainter::UpdateLeftViewXInset(int left_view_x_inset) {
240 int window_icon_size) { 229 int old_inset = left_view_x_inset_;
241 window_icon_ = window_icon; 230 left_view_x_inset_ = left_view_x_inset;
242 window_icon_size_ = window_icon_size; 231 if (old_inset != left_view_x_inset_)
232 LayoutLeftHeaderView();
pkotwicz 2014/08/19 00:17:07 Nit - This is slightly shorter: if (left_view_x_i
benwells 2014/08/19 01:42:42 Done.
233 }
234
235 void DefaultHeaderPainter::UpdateLeftHeaderView(views::View* left_header_view) {
236 left_header_view_ = left_header_view;
243 } 237 }
244 238
245 /////////////////////////////////////////////////////////////////////////////// 239 ///////////////////////////////////////////////////////////////////////////////
246 // gfx::AnimationDelegate overrides: 240 // gfx::AnimationDelegate overrides:
247 241
248 void DefaultHeaderPainter::AnimationProgressed( 242 void DefaultHeaderPainter::AnimationProgressed(
249 const gfx::Animation* animation) { 243 const gfx::Animation* animation) {
250 view_->SchedulePaintInRect(GetLocalBounds()); 244 view_->SchedulePaintInRect(GetLocalBounds());
251 } 245 }
252 246
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 SkPaint paint; 300 SkPaint paint;
307 paint.setColor(color); 301 paint.setColor(color);
308 // Draw the line as 1px thick regardless of scale factor. 302 // Draw the line as 1px thick regardless of scale factor.
309 paint.setStrokeWidth(0); 303 paint.setStrokeWidth(0);
310 304
311 float thickness = 1 / canvas->image_scale(); 305 float thickness = 1 / canvas->image_scale();
312 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness); 306 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness);
313 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint); 307 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint);
314 } 308 }
315 309
310 void DefaultHeaderPainter::LayoutLeftHeaderView() {
311 if (left_header_view_) {
312 // Vertically center the left header view with respect to the caption button
313 // container.
314 // Floor when computing the center of |caption_button_container_|.
315 int icon_offset_y = caption_button_container_->height() / 2 -
316 left_header_view_->height() / 2;
pkotwicz 2014/08/19 00:17:07 Shouldn't this be size.height() instead of left_he
benwells 2014/08/19 01:42:42 Done.
317 gfx::Size size = left_header_view_->GetPreferredSize();
318 left_header_view_->SetBounds(
319 left_view_x_inset_, icon_offset_y, size.width(), size.height());
320 }
321 }
322
316 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { 323 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const {
317 return gfx::Rect(view_->width(), height_); 324 return gfx::Rect(view_->width(), height_);
318 } 325 }
319 326
320 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { 327 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const {
321 return HeaderPainterUtil::GetTitleBounds( 328 return HeaderPainterUtil::GetTitleBounds(
322 window_icon_, caption_button_container_, GetTitleFontList()); 329 left_header_view_, caption_button_container_, GetTitleFontList());
323 } 330 }
324 331
325 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const { 332 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const {
326 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 333 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
327 IDR_AURA_WINDOW_HEADER_BASE); 334 IDR_AURA_WINDOW_HEADER_BASE);
328 } 335 }
329 336
330 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const { 337 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const {
331 int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ? 338 int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ?
332 IDR_AURA_WINDOW_HEADER_BASE : 339 IDR_AURA_WINDOW_HEADER_BASE :
333 IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE; 340 IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE;
334 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 341 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
335 frame_image_id); 342 frame_image_id);
336 } 343 }
337 344
338 } // namespace ash 345 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698