| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } // namespace | 70 } // namespace |
| 71 | 71 |
| 72 namespace ash { | 72 namespace ash { |
| 73 | 73 |
| 74 /////////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////////// |
| 75 // DefaultHeaderPainter, public: | 75 // DefaultHeaderPainter, public: |
| 76 | 76 |
| 77 DefaultHeaderPainter::DefaultHeaderPainter() | 77 DefaultHeaderPainter::DefaultHeaderPainter() |
| 78 : frame_(NULL), | 78 : frame_(NULL), |
| 79 view_(NULL), | 79 view_(NULL), |
| 80 window_icon_(NULL), | 80 left_header_view_(NULL), |
| 81 window_icon_size_(HeaderPainterUtil::GetDefaultIconSize()), | 81 left_view_x_inset_(HeaderPainterUtil::GetDefaultLeftViewXInset()), |
| 82 caption_button_container_(NULL), | 82 caption_button_container_(NULL), |
| 83 height_(0), | 83 height_(0), |
| 84 mode_(MODE_INACTIVE), | 84 mode_(MODE_INACTIVE), |
| 85 initial_paint_(true), | 85 initial_paint_(true), |
| 86 activation_animation_(new gfx::SlideAnimation(this)) { | 86 activation_animation_(new gfx::SlideAnimation(this)) { |
| 87 } | 87 } |
| 88 | 88 |
| 89 DefaultHeaderPainter::~DefaultHeaderPainter() { | 89 DefaultHeaderPainter::~DefaultHeaderPainter() { |
| 90 } | 90 } |
| 91 | 91 |
| 92 void DefaultHeaderPainter::Init( | 92 void DefaultHeaderPainter::Init( |
| 93 views::Widget* frame, | 93 views::Widget* frame, |
| 94 views::View* header_view, | 94 views::View* header_view, |
| 95 views::View* window_icon, | |
| 96 FrameCaptionButtonContainerView* caption_button_container) { | 95 FrameCaptionButtonContainerView* caption_button_container) { |
| 97 DCHECK(frame); | 96 DCHECK(frame); |
| 98 DCHECK(header_view); | 97 DCHECK(header_view); |
| 99 // window_icon may be NULL. | |
| 100 DCHECK(caption_button_container); | 98 DCHECK(caption_button_container); |
| 101 frame_ = frame; | 99 frame_ = frame; |
| 102 view_ = header_view; | 100 view_ = header_view; |
| 103 window_icon_ = window_icon; | |
| 104 caption_button_container_ = caption_button_container; | 101 caption_button_container_ = caption_button_container; |
| 105 | 102 |
| 106 caption_button_container_->SetButtonImages( | 103 caption_button_container_->SetButtonImages( |
| 107 CAPTION_BUTTON_ICON_MINIMIZE, | 104 CAPTION_BUTTON_ICON_MINIMIZE, |
| 108 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, | 105 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE, |
| 109 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, | 106 IDR_AURA_WINDOW_CONTROL_ICON_MINIMIZE_I, |
| 110 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, | 107 IDR_AURA_WINDOW_CONTROL_BACKGROUND_H, |
| 111 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); | 108 IDR_AURA_WINDOW_CONTROL_BACKGROUND_P); |
| 112 caption_button_container_->SetButtonImages( | 109 caption_button_container_->SetButtonImages( |
| 113 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, | 110 CAPTION_BUTTON_ICON_MAXIMIZE_RESTORE, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 caption_button_container_->Layout(); | 189 caption_button_container_->Layout(); |
| 193 | 190 |
| 194 gfx::Size caption_button_container_size = | 191 gfx::Size caption_button_container_size = |
| 195 caption_button_container_->GetPreferredSize(); | 192 caption_button_container_->GetPreferredSize(); |
| 196 caption_button_container_->SetBounds( | 193 caption_button_container_->SetBounds( |
| 197 view_->width() - caption_button_container_size.width(), | 194 view_->width() - caption_button_container_size.width(), |
| 198 0, | 195 0, |
| 199 caption_button_container_size.width(), | 196 caption_button_container_size.width(), |
| 200 caption_button_container_size.height()); | 197 caption_button_container_size.height()); |
| 201 | 198 |
| 202 if (window_icon_) { | 199 LayoutLeftHeaderView(); |
| 203 // Vertically center the window icon with respect to the caption button | |
| 204 // container. | |
| 205 // Floor when computing the center of |caption_button_container_|. | |
| 206 int icon_offset_y = | |
| 207 caption_button_container_->height() / 2 - window_icon_size_ / 2; | |
| 208 window_icon_->SetBounds(HeaderPainterUtil::GetIconXOffset(), icon_offset_y, | |
| 209 window_icon_size_, window_icon_size_); | |
| 210 } | |
| 211 | 200 |
| 212 // The header/content separator line overlays the caption buttons. | 201 // The header/content separator line overlays the caption buttons. |
| 213 SetHeaderHeightForPainting(caption_button_container_->height()); | 202 SetHeaderHeightForPainting(caption_button_container_->height()); |
| 214 } | 203 } |
| 215 | 204 |
| 216 int DefaultHeaderPainter::GetHeaderHeightForPainting() const { | 205 int DefaultHeaderPainter::GetHeaderHeightForPainting() const { |
| 217 return height_; | 206 return height_; |
| 218 } | 207 } |
| 219 | 208 |
| 220 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) { | 209 void DefaultHeaderPainter::SetHeaderHeightForPainting(int height) { |
| 221 height_ = height; | 210 height_ = height; |
| 222 } | 211 } |
| 223 | 212 |
| 224 void DefaultHeaderPainter::SchedulePaintForTitle() { | 213 void DefaultHeaderPainter::SchedulePaintForTitle() { |
| 225 view_->SchedulePaintInRect(GetTitleBounds()); | 214 view_->SchedulePaintInRect(GetTitleBounds()); |
| 226 } | 215 } |
| 227 | 216 |
| 228 void DefaultHeaderPainter::UpdateWindowIcon(views::View* window_icon, | 217 void DefaultHeaderPainter::UpdateLeftViewXInset(int left_view_x_inset) { |
| 229 int window_icon_size) { | 218 if (left_view_x_inset_ != left_view_x_inset) { |
| 230 window_icon_ = window_icon; | 219 left_view_x_inset_ = left_view_x_inset; |
| 231 window_icon_size_ = window_icon_size; | 220 LayoutLeftHeaderView(); |
| 221 } |
| 222 } |
| 223 |
| 224 void DefaultHeaderPainter::UpdateLeftHeaderView(views::View* left_header_view) { |
| 225 left_header_view_ = left_header_view; |
| 232 } | 226 } |
| 233 | 227 |
| 234 /////////////////////////////////////////////////////////////////////////////// | 228 /////////////////////////////////////////////////////////////////////////////// |
| 235 // gfx::AnimationDelegate overrides: | 229 // gfx::AnimationDelegate overrides: |
| 236 | 230 |
| 237 void DefaultHeaderPainter::AnimationProgressed( | 231 void DefaultHeaderPainter::AnimationProgressed( |
| 238 const gfx::Animation* animation) { | 232 const gfx::Animation* animation) { |
| 239 view_->SchedulePaintInRect(GetLocalBounds()); | 233 view_->SchedulePaintInRect(GetLocalBounds()); |
| 240 } | 234 } |
| 241 | 235 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 SkPaint paint; | 289 SkPaint paint; |
| 296 paint.setColor(color); | 290 paint.setColor(color); |
| 297 // Draw the line as 1px thick regardless of scale factor. | 291 // Draw the line as 1px thick regardless of scale factor. |
| 298 paint.setStrokeWidth(0); | 292 paint.setStrokeWidth(0); |
| 299 | 293 |
| 300 float thickness = 1 / canvas->image_scale(); | 294 float thickness = 1 / canvas->image_scale(); |
| 301 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness); | 295 SkScalar y = SkIntToScalar(height_) - SkFloatToScalar(thickness); |
| 302 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint); | 296 canvas->sk_canvas()->drawLine(0, y, SkIntToScalar(view_->width()), y, paint); |
| 303 } | 297 } |
| 304 | 298 |
| 299 void DefaultHeaderPainter::LayoutLeftHeaderView() { |
| 300 if (left_header_view_) { |
| 301 // Vertically center the left header view with respect to the caption button |
| 302 // container. |
| 303 // Floor when computing the center of |caption_button_container_|. |
| 304 gfx::Size size = left_header_view_->GetPreferredSize(); |
| 305 int icon_offset_y = caption_button_container_->height() / 2 - |
| 306 size.height() / 2; |
| 307 left_header_view_->SetBounds( |
| 308 left_view_x_inset_, icon_offset_y, size.width(), size.height()); |
| 309 } |
| 310 } |
| 311 |
| 305 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { | 312 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { |
| 306 return gfx::Rect(view_->width(), height_); | 313 return gfx::Rect(view_->width(), height_); |
| 307 } | 314 } |
| 308 | 315 |
| 309 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { | 316 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { |
| 310 return HeaderPainterUtil::GetTitleBounds( | 317 return HeaderPainterUtil::GetTitleBounds( |
| 311 window_icon_, caption_button_container_, GetTitleFontList()); | 318 left_header_view_, caption_button_container_, GetTitleFontList()); |
| 312 } | 319 } |
| 313 | 320 |
| 314 SkColor DefaultHeaderPainter::GetInactiveFrameColor() const { | 321 SkColor DefaultHeaderPainter::GetInactiveFrameColor() const { |
| 315 SkColor color = kFrameColor; | 322 SkColor color = kFrameColor; |
| 316 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) { | 323 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) { |
| 317 color = SkColorSetARGB(kInactiveFrameAlpha, | 324 color = SkColorSetARGB(kInactiveFrameAlpha, |
| 318 SkColorGetR(color), | 325 SkColorGetR(color), |
| 319 SkColorGetG(color), | 326 SkColorGetG(color), |
| 320 SkColorGetB(color)); | 327 SkColorGetB(color)); |
| 321 } | 328 } |
| 322 return color; | 329 return color; |
| 323 } | 330 } |
| 324 | 331 |
| 325 } // namespace ash | 332 } // namespace ash |
| OLD | NEW |