| 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 "chrome/browser/ui/views/frame/browser_header_painter_ash.h" | 5 #include "chrome/browser/ui/views/frame/browser_header_painter_ash.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_layout_constants.h" | 7 #include "ash/common/ash_layout_constants.h" |
| 8 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" | 8 #include "ash/common/frame/caption_buttons/frame_caption_button_container_view.h
" |
| 9 #include "ash/common/frame/header_painter_util.h" | 9 #include "ash/common/frame/header_painter_util.h" |
| 10 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
| 11 #include "base/logging.h" // DCHECK | 11 #include "base/logging.h" |
| 12 #include "chrome/browser/themes/theme_properties.h" | 12 #include "chrome/browser/themes/theme_properties.h" |
| 13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/views/frame/browser_frame.h" | 14 #include "chrome/browser/ui/views/frame/browser_frame.h" |
| 15 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" | 15 #include "chrome/browser/ui/views/frame/browser_non_client_frame_view_ash.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/core/SkCanvas.h" |
| 18 #include "third_party/skia/include/core/SkColor.h" | 18 #include "third_party/skia/include/core/SkColor.h" |
| 19 #include "third_party/skia/include/core/SkPaint.h" | 19 #include "third_party/skia/include/core/SkPaint.h" |
| 20 #include "third_party/skia/include/core/SkPath.h" | 20 #include "third_party/skia/include/core/SkPath.h" |
| 21 #include "ui/gfx/animation/slide_animation.h" | 21 #include "ui/gfx/animation/slide_animation.h" |
| 22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
| 23 #include "ui/gfx/geometry/rect.h" | 23 #include "ui/gfx/geometry/rect.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/scoped_canvas.h" |
| 25 #include "ui/gfx/skia_util.h" | 26 #include "ui/gfx/skia_util.h" |
| 26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| 27 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 28 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
| 29 | 30 |
| 30 using views::Widget; | 31 using views::Widget; |
| 31 | 32 |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // Color for the window title text. | 35 // Color for the window title text. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 SkPath path; | 54 SkPath path; |
| 54 path.addRoundRect(rect, radii, SkPath::kCW_Direction); | 55 path.addRoundRect(rect, radii, SkPath::kCW_Direction); |
| 55 return path; | 56 return path; |
| 56 } | 57 } |
| 57 | 58 |
| 58 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top | 59 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top |
| 59 // corners. | 60 // corners. |
| 60 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, | 61 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, |
| 61 const gfx::ImageSkia& frame_image, | 62 const gfx::ImageSkia& frame_image, |
| 62 const gfx::ImageSkia& frame_overlay_image, | 63 const gfx::ImageSkia& frame_overlay_image, |
| 63 const cc::PaintFlags& flags, | 64 int alpha, |
| 65 SkColor background_color, |
| 64 const gfx::Rect& bounds, | 66 const gfx::Rect& bounds, |
| 65 int corner_radius, | 67 int corner_radius, |
| 66 int image_inset_x) { | 68 int image_inset_x) { |
| 67 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius); | 69 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius); |
| 68 // If |flags| is using an unusual SkBlendMode (this is the case while | 70 bool antialias = corner_radius > 0; |
| 69 // crossfading), we must create a new canvas to overlay |frame_image| and | 71 |
| 70 // |frame_overlay_image| using |kSrcOver| and then paint the result | 72 gfx::ScopedCanvas scoped_save(canvas); |
| 71 // using the unusual mode. We try to avoid this because creating a new | 73 canvas->ClipPath(frame_path, antialias); |
| 72 // browser-width canvas is expensive. | 74 |
| 73 bool fast_path = (frame_overlay_image.isNull() || flags.isSrcOver()); | 75 cc::PaintFlags flags; |
| 74 if (fast_path) { | 76 flags.setBlendMode(SkBlendMode::kPlus); |
| 77 flags.setAntiAlias(antialias); |
| 78 |
| 79 if (frame_image.isNull() && frame_overlay_image.isNull()) { |
| 80 flags.setColor(background_color); |
| 81 canvas->DrawRect(bounds, flags); |
| 82 } else if (frame_overlay_image.isNull()) { |
| 83 flags.setAlpha(alpha); |
| 84 canvas->DrawImageInt(frame_image, -image_inset_x, 0, flags); |
| 85 } else { |
| 86 flags.setAlpha(alpha); |
| 87 canvas->SaveLayerWithFlags(flags); |
| 88 |
| 75 if (frame_image.isNull()) { | 89 if (frame_image.isNull()) { |
| 76 canvas->DrawPath(frame_path, flags); | 90 canvas->DrawColor(background_color); |
| 77 } else { | 91 } else { |
| 78 canvas->DrawImageInPath(frame_image, -image_inset_x, 0, frame_path, | 92 canvas->TileImageInt(frame_image, image_inset_x, 0, 0, 0, bounds.width(), |
| 79 flags); | 93 bounds.height()); |
| 80 } | 94 } |
| 95 canvas->DrawImageInt(frame_overlay_image, 0, 0); |
| 81 | 96 |
| 82 if (!frame_overlay_image.isNull()) { | 97 canvas->Restore(); |
| 83 // Adjust |bounds| such that |frame_overlay_image| is not tiled. | |
| 84 gfx::Rect overlay_bounds = bounds; | |
| 85 overlay_bounds.Intersect( | |
| 86 gfx::Rect(bounds.origin(), frame_overlay_image.size())); | |
| 87 int top_left_corner_radius = corner_radius; | |
| 88 int top_right_corner_radius = corner_radius; | |
| 89 if (overlay_bounds.width() < bounds.width() - corner_radius) | |
| 90 top_right_corner_radius = 0; | |
| 91 canvas->DrawImageInPath( | |
| 92 frame_overlay_image, 0, 0, | |
| 93 MakeRoundRectPath(overlay_bounds, top_left_corner_radius, | |
| 94 top_right_corner_radius), | |
| 95 flags); | |
| 96 } | |
| 97 } else { | |
| 98 gfx::Canvas temporary_canvas(bounds.size(), canvas->image_scale(), false); | |
| 99 if (frame_image.isNull()) { | |
| 100 temporary_canvas.DrawColor(flags.getColor()); | |
| 101 } else { | |
| 102 temporary_canvas.TileImageInt(frame_image, image_inset_x, 0, 0, 0, | |
| 103 bounds.width(), bounds.height()); | |
| 104 } | |
| 105 temporary_canvas.DrawImageInt(frame_overlay_image, 0, 0); | |
| 106 canvas->DrawImageInPath(gfx::ImageSkia(temporary_canvas.ExtractImageRep()), | |
| 107 0, 0, frame_path, flags); | |
| 108 } | 98 } |
| 109 } | 99 } |
| 110 | 100 |
| 111 } // namespace | 101 } // namespace |
| 112 | 102 |
| 113 /////////////////////////////////////////////////////////////////////////////// | 103 /////////////////////////////////////////////////////////////////////////////// |
| 114 // BrowserHeaderPainterAsh, public: | 104 // BrowserHeaderPainterAsh, public: |
| 115 | 105 |
| 116 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh() | 106 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh() |
| 117 : frame_(nullptr), | 107 : frame_(nullptr), |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 239 |
| 250 void BrowserHeaderPainterAsh::PaintFrameImages(gfx::Canvas* canvas, | 240 void BrowserHeaderPainterAsh::PaintFrameImages(gfx::Canvas* canvas, |
| 251 bool active) { | 241 bool active) { |
| 252 int alpha = activation_animation_->CurrentValueBetween(0, 0xFF); | 242 int alpha = activation_animation_->CurrentValueBetween(0, 0xFF); |
| 253 if (!active) | 243 if (!active) |
| 254 alpha = 0xFF - alpha; | 244 alpha = 0xFF - alpha; |
| 255 | 245 |
| 256 if (alpha == 0) | 246 if (alpha == 0) |
| 257 return; | 247 return; |
| 258 | 248 |
| 259 bool round_corners = !frame_->IsMaximized() && !frame_->IsFullscreen(); | |
| 260 gfx::ImageSkia frame_image = view_->GetFrameImage(active); | 249 gfx::ImageSkia frame_image = view_->GetFrameImage(active); |
| 261 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active); | 250 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active); |
| 251 SkColor background_color = SkColorSetA(view_->GetFrameColor(active), alpha); |
| 262 | 252 |
| 263 cc::PaintFlags flags; | 253 int corner_radius = 0; |
| 264 flags.setBlendMode(SkBlendMode::kPlus); | 254 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) |
| 265 flags.setAlpha(alpha); | 255 corner_radius = ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored(); |
| 266 flags.setColor(SkColorSetA(view_->GetFrameColor(active), alpha)); | 256 |
| 267 flags.setAntiAlias(round_corners); | |
| 268 PaintFrameImagesInRoundRect( | 257 PaintFrameImagesInRoundRect( |
| 269 canvas, frame_image, frame_overlay_image, flags, GetPaintedBounds(), | 258 canvas, frame_image, frame_overlay_image, alpha, background_color, |
| 270 round_corners ? ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored() | 259 GetPaintedBounds(), corner_radius, |
| 271 : 0, | |
| 272 ash::HeaderPainterUtil::GetThemeBackgroundXInset()); | 260 ash::HeaderPainterUtil::GetThemeBackgroundXInset()); |
| 273 } | 261 } |
| 274 | 262 |
| 275 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) { | 263 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) { |
| 276 // The window icon is painted by its own views::View. | 264 // The window icon is painted by its own views::View. |
| 277 gfx::Rect title_bounds = GetTitleBounds(); | 265 gfx::Rect title_bounds = GetTitleBounds(); |
| 278 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); | 266 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); |
| 279 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), | 267 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), |
| 280 BrowserFrame::GetTitleFontList(), | 268 BrowserFrame::GetTitleFontList(), |
| 281 is_incognito_ ? kIncognitoWindowTitleTextColor | 269 is_incognito_ ? kIncognitoWindowTitleTextColor |
| (...skipping 28 matching lines...) Expand all Loading... |
| 310 } | 298 } |
| 311 | 299 |
| 312 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const { | 300 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const { |
| 313 return gfx::Rect(view_->width(), painted_height_); | 301 return gfx::Rect(view_->width(), painted_height_); |
| 314 } | 302 } |
| 315 | 303 |
| 316 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const { | 304 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const { |
| 317 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_, | 305 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_, |
| 318 caption_button_container_, BrowserFrame::GetTitleFontList()); | 306 caption_button_container_, BrowserFrame::GetTitleFontList()); |
| 319 } | 307 } |
| OLD | NEW |