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 "core/paint/ScrollableAreaPainter.h" | 5 #include "core/paint/ScrollableAreaPainter.h" |
| 6 | 6 |
| 7 #include "core/layout/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
| 8 #include "core/page/Page.h" | 8 #include "core/page/Page.h" |
| 9 #include "core/paint/LayoutObjectDrawingRecorder.h" | 9 #include "core/paint/LayoutObjectDrawingRecorder.h" |
| 10 #include "core/paint/ObjectPaintProperties.h" | 10 #include "core/paint/ObjectPaintProperties.h" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 context.SetStrokeColor(Color(217, 217, 217)); | 63 context.SetStrokeColor(Color(217, 217, 217)); |
| 64 context.SetStrokeThickness(1.0f); | 64 context.SetStrokeThickness(1.0f); |
| 65 context.SetFillColor(Color::kTransparent); | 65 context.SetFillColor(Color::kTransparent); |
| 66 context.DrawRect(larger_corner); | 66 context.DrawRect(larger_corner); |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ScrollableAreaPainter::DrawPlatformResizerImage( | 70 void ScrollableAreaPainter::DrawPlatformResizerImage( |
| 71 GraphicsContext& context, | 71 GraphicsContext& context, |
| 72 IntRect resizer_corner_rect) { | 72 IntRect resizer_corner_rect) { |
| 73 float old_device_scale_factor = | 73 PaintFlags paint_flags; |
| 74 blink::DeviceScaleFactorDeprecated(GetScrollableArea().Box().GetFrame()); | 74 paint_flags.setStyle(PaintFlags::kStroke_Style); |
| 75 // |blink::deviceScaleFactor| returns different values between MAC (2 or 1) | 75 paint_flags.setStrokeWidth(1); |
| 76 // and other platforms (always 1). For this reason we cannot hardcode the | 76 SkPath line_path; |
| 77 // value of 1 in the call for |windowToViewportScalar|. Since zoom-for-dsf is | |
| 78 // disabled on MAC, |windowToViewportScalar| will be a no-op on it. | |
| 79 float device_scale_factor = | |
| 80 GetScrollableArea().GetChromeClient()->WindowToViewportScalar( | |
| 81 old_device_scale_factor); | |
| 82 | 77 |
| 83 RefPtr<Image> resize_corner_image; | 78 auto paint_resizer_line = [&context, &paint_flags, &line_path]( |
| 84 IntSize corner_resizer_size; | 79 IntPoint& start, IntPoint& end, bool on_left) { |
| 85 if (device_scale_factor >= 2) { | 80 line_path.rewind(); |
| 86 DEFINE_STATIC_REF(Image, resize_corner_image_hi_res, | 81 line_path.moveTo(start.X(), start.Y()); |
| 87 (Image::LoadPlatformResource("textAreaResizeCorner@2x"))); | 82 line_path.lineTo(end.X(), end.Y()); |
| 88 resize_corner_image = resize_corner_image_hi_res; | 83 paint_flags.setARGB(153, 0, 0, 0); |
| 89 corner_resizer_size = resize_corner_image->Size(); | 84 context.DrawPath(line_path, paint_flags); |
|
f(malita)
2017/04/26 17:56:33
Can we use DrawLine instead?
(DrawPoints would be
| |
| 90 if (old_device_scale_factor >= 2) | 85 line_path.rewind(); |
| 91 corner_resizer_size.Scale(0.5f); | 86 line_path.moveTo(start.X(), start.Y() + 1); |
| 92 } else { | 87 line_path.lineTo(end.X() + (on_left ? -1 : 1), end.Y()); |
| 93 DEFINE_STATIC_REF(Image, resize_corner_image_lo_res, | 88 paint_flags.setARGB(153, 255, 255, 255); |
| 94 (Image::LoadPlatformResource("textAreaResizeCorner"))); | 89 context.DrawPath(line_path, paint_flags); |
| 95 resize_corner_image = resize_corner_image_lo_res; | 90 }; |
| 96 corner_resizer_size = resize_corner_image->Size(); | |
| 97 } | |
| 98 | 91 |
| 99 if (GetScrollableArea() | 92 if (GetScrollableArea() |
| 100 .Box() | 93 .Box() |
| 101 .ShouldPlaceBlockDirectionScrollbarOnLogicalLeft()) { | 94 .ShouldPlaceBlockDirectionScrollbarOnLogicalLeft()) { |
| 102 context.Save(); | 95 IntPoint start_pt( |
| 103 context.Translate(resizer_corner_rect.X() + corner_resizer_size.Width(), | 96 resizer_corner_rect.X() + 1, |
| 104 resizer_corner_rect.Y() + resizer_corner_rect.Height() - | 97 resizer_corner_rect.Y() + resizer_corner_rect.Height() / 2); |
| 105 corner_resizer_size.Height()); | 98 IntPoint end_pt(resizer_corner_rect.X() + resizer_corner_rect.Width() - |
| 106 context.Scale(-1.0, 1.0); | 99 resizer_corner_rect.Width() / 2, |
|
Stephen Chennney
2017/04/25 20:55:28
While this seems like a roundabout way to do it, i
| |
| 107 context.DrawImage(resize_corner_image.Get(), | 100 resizer_corner_rect.Y() + resizer_corner_rect.Height() - 1); |
| 108 IntRect(IntPoint(), corner_resizer_size)); | 101 paint_resizer_line(start_pt, end_pt, true); |
| 109 context.Restore(); | 102 |
| 103 start_pt.SetY(resizer_corner_rect.Y() + | |
| 104 resizer_corner_rect.Height() * 3 / 4); | |
| 105 end_pt.SetX(resizer_corner_rect.X() + resizer_corner_rect.Width() - | |
| 106 resizer_corner_rect.Width() * 3 / 4); | |
|
Stephen Chennney
2017/04/25 20:55:28
Ditto.
| |
| 107 paint_resizer_line(start_pt, end_pt, true); | |
| 110 return; | 108 return; |
| 111 } | 109 } |
|
f(malita)
2017/04/26 17:56:34
I'm thinking we can merge part of these branches,
| |
| 112 IntRect image_rect(resizer_corner_rect.MaxXMaxYCorner() - corner_resizer_size, | 110 |
| 113 corner_resizer_size); | 111 IntPoint start_pt(resizer_corner_rect.X() + resizer_corner_rect.Width() - 1, |
| 114 context.DrawImage(resize_corner_image.Get(), image_rect); | 112 resizer_corner_rect.Y() + resizer_corner_rect.Height() / 2); |
| 113 IntPoint end_pt(resizer_corner_rect.X() + resizer_corner_rect.Width() / 2, | |
| 114 resizer_corner_rect.Y() + resizer_corner_rect.Height() - 1); | |
| 115 paint_resizer_line(start_pt, end_pt, false); | |
| 116 | |
| 117 start_pt.SetY(resizer_corner_rect.Y() + resizer_corner_rect.Height() * 3 / 4); | |
| 118 end_pt.SetX(resizer_corner_rect.X() + resizer_corner_rect.Width() * 3 / 4); | |
| 119 paint_resizer_line(start_pt, end_pt, false); | |
| 115 } | 120 } |
| 116 | 121 |
| 117 void ScrollableAreaPainter::PaintOverflowControls( | 122 void ScrollableAreaPainter::PaintOverflowControls( |
| 118 GraphicsContext& context, | 123 GraphicsContext& context, |
| 119 const IntPoint& paint_offset, | 124 const IntPoint& paint_offset, |
| 120 const CullRect& cull_rect, | 125 const CullRect& cull_rect, |
| 121 bool painting_overlay_controls) { | 126 bool painting_overlay_controls) { |
| 122 // Don't do anything if we have no overflow. | 127 // Don't do anything if we have no overflow. |
| 123 if (!GetScrollableArea().Box().HasOverflowClip()) | 128 if (!GetScrollableArea().Box().HasOverflowClip()) |
| 124 return; | 129 return; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 LayoutObjectDrawingRecorder recorder(context, GetScrollableArea().Box(), | 274 LayoutObjectDrawingRecorder recorder(context, GetScrollableArea().Box(), |
| 270 DisplayItem::kScrollbarCorner, abs_rect); | 275 DisplayItem::kScrollbarCorner, abs_rect); |
| 271 context.FillRect(abs_rect, Color::kWhite); | 276 context.FillRect(abs_rect, Color::kWhite); |
| 272 } | 277 } |
| 273 | 278 |
| 274 PaintLayerScrollableArea& ScrollableAreaPainter::GetScrollableArea() const { | 279 PaintLayerScrollableArea& ScrollableAreaPainter::GetScrollableArea() const { |
| 275 return *scrollable_area_; | 280 return *scrollable_area_; |
| 276 } | 281 } |
| 277 | 282 |
| 278 } // namespace blink | 283 } // namespace blink |
| OLD | NEW |