Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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_header_view_size_(0), |
| 79 left_header_view_offset_(0), | |
| 79 caption_button_container_(NULL), | 80 caption_button_container_(NULL), |
| 80 height_(0), | 81 height_(0), |
| 81 mode_(MODE_INACTIVE), | 82 mode_(MODE_INACTIVE), |
| 82 initial_paint_(true), | 83 initial_paint_(true), |
| 83 activation_animation_(new gfx::SlideAnimation(this)) { | 84 activation_animation_(new gfx::SlideAnimation(this)) { |
| 84 } | 85 } |
| 85 | 86 |
| 86 DefaultHeaderPainter::~DefaultHeaderPainter() { | 87 DefaultHeaderPainter::~DefaultHeaderPainter() { |
| 87 } | 88 } |
| 88 | 89 |
| 89 void DefaultHeaderPainter::Init( | 90 void DefaultHeaderPainter::Init( |
| 90 views::Widget* frame, | 91 views::Widget* frame, |
| 91 views::View* header_view, | 92 views::View* header_view, |
| 92 views::View* window_icon, | |
| 93 FrameCaptionButtonContainerView* caption_button_container) { | 93 FrameCaptionButtonContainerView* caption_button_container) { |
| 94 DCHECK(frame); | 94 DCHECK(frame); |
| 95 DCHECK(header_view); | 95 DCHECK(header_view); |
| 96 // window_icon may be NULL. | |
| 97 DCHECK(caption_button_container); | 96 DCHECK(caption_button_container); |
| 98 frame_ = frame; | 97 frame_ = frame; |
| 99 view_ = header_view; | 98 view_ = header_view; |
| 100 window_icon_ = window_icon; | |
| 101 caption_button_container_ = caption_button_container; | 99 caption_button_container_ = caption_button_container; |
| 102 | 100 |
| 103 caption_button_container_->SetButtonImages( | 101 caption_button_container_->SetButtonImages( |
| 104 CAPTION_BUTTON_ICON_MINIMIZE, | 102 CAPTION_BUTTON_ICON_MINIMIZE, |
| 105 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, | 103 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, |
| 106 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, | 104 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, |
| 107 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | 105 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, |
| 108 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | 106 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); |
| 109 caption_button_container_->SetButtonImages( | 107 caption_button_container_->SetButtonImages( |
| 110 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, | 108 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 caption_button_container_->Layout(); | 201 caption_button_container_->Layout(); |
| 204 | 202 |
| 205 gfx::Size caption_button_container_size = | 203 gfx::Size caption_button_container_size = |
| 206 caption_button_container_->GetPreferredSize(); | 204 caption_button_container_->GetPreferredSize(); |
| 207 caption_button_container_->SetBounds( | 205 caption_button_container_->SetBounds( |
| 208 view_->width() - caption_button_container_size.width(), | 206 view_->width() - caption_button_container_size.width(), |
| 209 0, | 207 0, |
| 210 caption_button_container_size.width(), | 208 caption_button_container_size.width(), |
| 211 caption_button_container_size.height()); | 209 caption_button_container_size.height()); |
| 212 | 210 |
| 213 if (window_icon_) { | 211 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 | 212 |
| 223 // The header/content separator line overlays the caption buttons. | 213 // The header/content separator line overlays the caption buttons. |
| 224 SetHeaderHeightForPainting(caption_button_container_->height()); | 214 SetHeaderHeightForPainting(caption_button_container_->height()); |
| 225 } | 215 } |
| 226 | 216 |
| 227 int DefaultHeaderPainter::GetHeaderHeightForPainting() const { | 217 int DefaultHeaderPainter::GetHeaderHeightForPainting() const { |
| 228 return height_; | 218 return height_; |
| 229 } | 219 } |
| 230 | 220 |
| 231 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) { | 221 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) { |
| 232 height_ = height; | 222 height_ = height; |
| 233 } | 223 } |
| 234 | 224 |
| 235 void DefaultHeaderPainter::SchedulePaintForTitle() { | 225 void DefaultHeaderPainter::SchedulePaintForTitle() { |
| 236 view_->SchedulePaintInRect(GetTitleBounds()); | 226 view_->SchedulePaintInRect(GetTitleBounds()); |
| 237 } | 227 } |
| 238 | 228 |
| 239 void DefaultHeaderPainter::UpdateWindowIcon(views::View* window_icon, | 229 void DefaultHeaderPainter::UpdateHeaderOffset(int left_header_view_offset) { |
|
pkotwicz
2014/08/13 01:19:47
I think that |left_view_x_inset| is a better name.
benwells
2014/08/13 08:09:28
Done.
| |
| 240 int window_icon_size) { | 230 int old_offset = left_header_view_offset_; |
| 241 window_icon_ = window_icon; | 231 left_header_view_offset_ = left_header_view_offset; |
| 242 window_icon_size_ = window_icon_size; | 232 if (old_offset != left_header_view_offset_) |
| 233 LayoutLeftHeaderView(); | |
| 234 } | |
| 235 | |
| 236 void DefaultHeaderPainter::UpdateLeftHeaderView(views::View* left_header_view, | |
| 237 int left_header_view_size) { | |
| 238 left_header_view_ = left_header_view; | |
| 239 left_header_view_size_ = left_header_view_size; | |
| 243 } | 240 } |
| 244 | 241 |
| 245 /////////////////////////////////////////////////////////////////////////////// | 242 /////////////////////////////////////////////////////////////////////////////// |
| 246 // gfx::AnimationDelegate overrides: | 243 // gfx::AnimationDelegate overrides: |
| 247 | 244 |
| 248 void DefaultHeaderPainter::AnimationProgressed( | 245 void DefaultHeaderPainter::AnimationProgressed( |
| 249 const gfx::Animation* animation) { | 246 const gfx::Animation* animation) { |
| 250 view_->SchedulePaintInRect(GetLocalBounds()); | 247 view_->SchedulePaintInRect(GetLocalBounds()); |
| 251 } | 248 } |
| 252 | 249 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 SkPaint paint; | 303 SkPaint paint; |
| 307 paint.setColor(color); | 304 paint.setColor(color); |
| 308 // Draw the line as 1px thick regardless of scale factor. | 305 // Draw the line as 1px thick regardless of scale factor. |
| 309 paint.setStrokeWidth(0); | 306 paint.setStrokeWidth(0); |
| 310 | 307 |
| 311 float thickness = 1 / canvas->image_scale(); | 308 float thickness = 1 / canvas->image_scale(); |
| 312 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness); | 309 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness); |
| 313 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint); | 310 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint); |
| 314 } | 311 } |
| 315 | 312 |
| 313 void DefaultHeaderPainter::LayoutLeftHeaderView() { | |
| 314 if (left_header_view_) { | |
| 315 // Vertically center the window icon with respect to the caption button | |
| 316 // container. | |
| 317 // Floor when computing the center of |caption_button_container_|. | |
| 318 int icon_offset_y = caption_button_container_->height() / 2 - | |
| 319 left_header_view_->height() / 2; | |
| 320 int offset = left_header_view_offset_ ? left_header_view_offset_ | |
| 321 : HeaderPainterUtil::GetIconXOffset(); | |
|
pkotwicz
2014/08/13 01:19:47
Nit: I think that checking equality to zero here w
benwells
2014/08/13 08:09:28
Done.
| |
| 322 left_header_view_->SetBounds( | |
| 323 offset, icon_offset_y, left_header_view_size_, left_header_view_size_); | |
|
pkotwicz
2014/08/13 01:19:47
Can we use left_header_view_->GetPreferredSize() a
benwells
2014/08/13 08:09:28
Seems so. The code sure is nicer! I hope it doesn'
| |
| 324 } | |
| 325 } | |
| 326 | |
| 316 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { | 327 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { |
| 317 return gfx::Rect(view_->width(), height_); | 328 return gfx::Rect(view_->width(), height_); |
| 318 } | 329 } |
| 319 | 330 |
| 320 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { | 331 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { |
| 321 return HeaderPainterUtil::GetTitleBounds( | 332 return HeaderPainterUtil::GetTitleBounds( |
| 322 window_icon_, caption_button_container_, GetTitleFontList()); | 333 left_header_view_, caption_button_container_, GetTitleFontList()); |
| 323 } | 334 } |
| 324 | 335 |
| 325 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const { | 336 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const { |
| 326 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 337 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 327 IDR_AURA_WINDOW_HEADER_BASE); | 338 IDR_AURA_WINDOW_HEADER_BASE); |
| 328 } | 339 } |
| 329 | 340 |
| 330 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const { | 341 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const { |
| 331 int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ? | 342 int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ? |
| 332 IDR_AURA_WINDOW_HEADER_BASE : | 343 IDR_AURA_WINDOW_HEADER_BASE : |
| 333 IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE; | 344 IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE; |
| 334 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 345 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 335 frame_image_id); | 346 frame_image_id); |
| 336 } | 347 } |
| 337 | 348 |
| 338 } // namespace ash | 349 } // namespace ash |
| OLD | NEW |