| 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_view_x_inset_(0), | 
| 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  Loading... | 
| 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(); | 
|  | 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  Loading... | 
| 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; | 
|  | 317     int inset = left_view_x_inset_ == 0 ? HeaderPainterUtil::GetIconXOffset() | 
|  | 318                                         : left_view_x_inset_; | 
|  | 319     gfx::Size size = left_header_view_->GetPreferredSize(); | 
|  | 320     left_header_view_->SetBounds( | 
|  | 321         inset, icon_offset_y, size.width(), size.height()); | 
|  | 322   } | 
|  | 323 } | 
|  | 324 | 
| 316 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { | 325 gfx::Rect DefaultHeaderPainter::GetLocalBounds() const { | 
| 317   return gfx::Rect(view_->width(), height_); | 326   return gfx::Rect(view_->width(), height_); | 
| 318 } | 327 } | 
| 319 | 328 | 
| 320 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { | 329 gfx::Rect DefaultHeaderPainter::GetTitleBounds() const { | 
| 321   return HeaderPainterUtil::GetTitleBounds( | 330   return HeaderPainterUtil::GetTitleBounds( | 
| 322       window_icon_, caption_button_container_, GetTitleFontList()); | 331       left_header_view_, caption_button_container_, GetTitleFontList()); | 
| 323 } | 332 } | 
| 324 | 333 | 
| 325 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const { | 334 gfx::ImageSkia* DefaultHeaderPainter::GetActiveFrameImage() const { | 
| 326   return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 335   return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 
| 327       IDR_AURA_WINDOW_HEADER_BASE); | 336       IDR_AURA_WINDOW_HEADER_BASE); | 
| 328 } | 337 } | 
| 329 | 338 | 
| 330 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const { | 339 gfx::ImageSkia* DefaultHeaderPainter::GetInactiveFrameImage() const { | 
| 331   int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ? | 340   int frame_image_id = (frame_->IsMaximized() || frame_->IsFullscreen()) ? | 
| 332       IDR_AURA_WINDOW_HEADER_BASE : | 341       IDR_AURA_WINDOW_HEADER_BASE : | 
| 333       IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE; | 342       IDR_AURA_WINDOW_HEADER_BASE_RESTORED_INACTIVE; | 
| 334   return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 343   return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 
| 335       frame_image_id); | 344       frame_image_id); | 
| 336 } | 345 } | 
| 337 | 346 | 
| 338 }  // namespace ash | 347 }  // namespace ash | 
| OLD | NEW | 
|---|