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 "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" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 SkPath path; | 53 SkPath path; |
| 54 path.addRoundRect(rect, radii, SkPath::kCW_Direction); | 54 path.addRoundRect(rect, radii, SkPath::kCW_Direction); |
| 55 return path; | 55 return path; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top | 58 // Tiles |frame_image| and |frame_overlay_image| into an area, rounding the top |
| 59 // corners. | 59 // corners. |
| 60 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, | 60 void PaintFrameImagesInRoundRect(gfx::Canvas* canvas, |
| 61 const gfx::ImageSkia& frame_image, | 61 const gfx::ImageSkia& frame_image, |
| 62 const gfx::ImageSkia& frame_overlay_image, | 62 const gfx::ImageSkia& frame_overlay_image, |
| 63 const cc::PaintFlags& flags, | 63 int alpha, |
| 64 SkColor background_color, | |
| 64 const gfx::Rect& bounds, | 65 const gfx::Rect& bounds, |
| 65 int corner_radius, | 66 int corner_radius, |
| 66 int image_inset_x) { | 67 int image_inset_x) { |
| 67 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius); | 68 SkPath frame_path = MakeRoundRectPath(bounds, corner_radius, corner_radius); |
| 68 // If |flags| is using an unusual SkBlendMode (this is the case while | 69 bool antialias = corner_radius > 0; |
| 69 // crossfading), we must create a new canvas to overlay |frame_image| and | 70 |
| 70 // |frame_overlay_image| using |kSrcOver| and then paint the result | 71 canvas->Save(); |
|
Peter Kasting
2017/03/22 22:25:57
Nit: Prefer ScopedCanvas to explicit Save()/Restor
danakj
2017/03/22 22:27:47
Oh thanks, I was looking for that.. but I thot it
| |
| 71 // using the unusual mode. We try to avoid this because creating a new | 72 canvas->ClipPath(frame_path, antialias); |
| 72 // browser-width canvas is expensive. | 73 |
| 73 bool fast_path = (frame_overlay_image.isNull() || flags.isSrcOver()); | 74 cc::PaintFlags flags; |
| 74 if (fast_path) { | 75 flags.setBlendMode(SkBlendMode::kPlus); |
| 76 flags.setAntiAlias(antialias); | |
| 77 | |
| 78 if (frame_image.isNull() && frame_overlay_image.isNull()) { | |
| 79 flags.setColor(background_color); | |
| 80 canvas->DrawRect(bounds, flags); | |
| 81 } else if (frame_overlay_image.isNull()) { | |
| 82 flags.setAlpha(alpha); | |
| 83 canvas->DrawImageInt(frame_image, -image_inset_x, 0, flags); | |
| 84 } else { | |
| 85 flags.setAlpha(alpha); | |
| 86 canvas->SaveLayerWithFlags(flags); | |
| 87 | |
| 75 if (frame_image.isNull()) { | 88 if (frame_image.isNull()) { |
| 76 canvas->DrawPath(frame_path, flags); | 89 canvas->DrawColor(background_color); |
| 77 } else { | 90 } else { |
| 78 canvas->DrawImageInPath(frame_image, -image_inset_x, 0, frame_path, | 91 canvas->TileImageInt(frame_image, image_inset_x, 0, 0, 0, bounds.width(), |
| 79 flags); | 92 bounds.height()); |
| 80 } | 93 } |
| 94 canvas->DrawImageInt(frame_overlay_image, 0, 0); | |
| 81 | 95 |
| 82 if (!frame_overlay_image.isNull()) { | 96 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 } | 97 } |
| 98 | |
| 99 canvas->Restore(); | |
| 109 } | 100 } |
| 110 | 101 |
| 111 } // namespace | 102 } // namespace |
| 112 | 103 |
| 113 /////////////////////////////////////////////////////////////////////////////// | 104 /////////////////////////////////////////////////////////////////////////////// |
| 114 // BrowserHeaderPainterAsh, public: | 105 // BrowserHeaderPainterAsh, public: |
| 115 | 106 |
| 116 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh() | 107 BrowserHeaderPainterAsh::BrowserHeaderPainterAsh() |
| 117 : frame_(nullptr), | 108 : frame_(nullptr), |
| 118 is_tabbed_(false), | 109 is_tabbed_(false), |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 | 240 |
| 250 void BrowserHeaderPainterAsh::PaintFrameImages(gfx::Canvas* canvas, | 241 void BrowserHeaderPainterAsh::PaintFrameImages(gfx::Canvas* canvas, |
| 251 bool active) { | 242 bool active) { |
| 252 int alpha = activation_animation_->CurrentValueBetween(0, 0xFF); | 243 int alpha = activation_animation_->CurrentValueBetween(0, 0xFF); |
| 253 if (!active) | 244 if (!active) |
| 254 alpha = 0xFF - alpha; | 245 alpha = 0xFF - alpha; |
| 255 | 246 |
| 256 if (alpha == 0) | 247 if (alpha == 0) |
| 257 return; | 248 return; |
| 258 | 249 |
| 259 bool round_corners = !frame_->IsMaximized() && !frame_->IsFullscreen(); | |
| 260 gfx::ImageSkia frame_image = view_->GetFrameImage(active); | 250 gfx::ImageSkia frame_image = view_->GetFrameImage(active); |
| 261 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active); | 251 gfx::ImageSkia frame_overlay_image = view_->GetFrameOverlayImage(active); |
| 252 SkColor background_color = SkColorSetA(view_->GetFrameColor(active), alpha); | |
| 262 | 253 |
| 263 cc::PaintFlags flags; | 254 int corner_radius = 0; |
| 264 flags.setBlendMode(SkBlendMode::kPlus); | 255 if (!frame_->IsMaximized() && !frame_->IsFullscreen()) |
| 265 flags.setAlpha(alpha); | 256 corner_radius = ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored(); |
| 266 flags.setColor(SkColorSetA(view_->GetFrameColor(active), alpha)); | 257 |
| 267 flags.setAntiAlias(round_corners); | |
| 268 PaintFrameImagesInRoundRect( | 258 PaintFrameImagesInRoundRect( |
| 269 canvas, frame_image, frame_overlay_image, flags, GetPaintedBounds(), | 259 canvas, frame_image, frame_overlay_image, alpha, background_color, |
| 270 round_corners ? ash::HeaderPainterUtil::GetTopCornerRadiusWhenRestored() | 260 GetPaintedBounds(), corner_radius, |
| 271 : 0, | |
| 272 ash::HeaderPainterUtil::GetThemeBackgroundXInset()); | 261 ash::HeaderPainterUtil::GetThemeBackgroundXInset()); |
| 273 } | 262 } |
| 274 | 263 |
| 275 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) { | 264 void BrowserHeaderPainterAsh::PaintTitleBar(gfx::Canvas* canvas) { |
| 276 // The window icon is painted by its own views::View. | 265 // The window icon is painted by its own views::View. |
| 277 gfx::Rect title_bounds = GetTitleBounds(); | 266 gfx::Rect title_bounds = GetTitleBounds(); |
| 278 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); | 267 title_bounds.set_x(view_->GetMirroredXForRect(title_bounds)); |
| 279 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), | 268 canvas->DrawStringRectWithFlags(frame_->widget_delegate()->GetWindowTitle(), |
| 280 BrowserFrame::GetTitleFontList(), | 269 BrowserFrame::GetTitleFontList(), |
| 281 is_incognito_ ? kIncognitoWindowTitleTextColor | 270 is_incognito_ ? kIncognitoWindowTitleTextColor |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 310 } | 299 } |
| 311 | 300 |
| 312 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const { | 301 gfx::Rect BrowserHeaderPainterAsh::GetPaintedBounds() const { |
| 313 return gfx::Rect(view_->width(), painted_height_); | 302 return gfx::Rect(view_->width(), painted_height_); |
| 314 } | 303 } |
| 315 | 304 |
| 316 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const { | 305 gfx::Rect BrowserHeaderPainterAsh::GetTitleBounds() const { |
| 317 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_, | 306 return ash::HeaderPainterUtil::GetTitleBounds(window_icon_, |
| 318 caption_button_container_, BrowserFrame::GetTitleFontList()); | 307 caption_button_container_, BrowserFrame::GetTitleFontList()); |
| 319 } | 308 } |
| OLD | NEW |