diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-20 10:33:36 +0100 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-11-22 11:45:12 +0000 |
commit | be59a35641616a4cf23c4a13fa0632624b021c1b (patch) | |
tree | 9da183258bdf9cc413f7562079d25ace6955467f /chromium/ui/views/view.h | |
parent | d702e4b6a64574e97fc7df8fe3238cde70242080 (diff) | |
download | qtwebengine-chromium-be59a35641616a4cf23c4a13fa0632624b021c1b.tar.gz |
BASELINE: Update Chromium to 62.0.3202.101
Change-Id: I2d5eca8117600df6d331f6166ab24d943d9814ac
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/ui/views/view.h')
-rw-r--r-- | chromium/ui/views/view.h | 151 |
1 files changed, 124 insertions, 27 deletions
diff --git a/chromium/ui/views/view.h b/chromium/ui/views/view.h index 7a8a7b327eb..33f393275cb 100644 --- a/chromium/ui/views/view.h +++ b/chromium/ui/views/view.h @@ -37,6 +37,7 @@ #include "ui/gfx/geometry/vector2d.h" #include "ui/gfx/native_widget_types.h" #include "ui/gfx/path.h" +#include "ui/views/paint_info.h" #include "ui/views/view_targeter.h" #include "ui/views/views_export.h" @@ -165,6 +166,96 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, View* move_view; }; + // During paint, the origin of each view in physical pixel is calculated by + // view_origin_pixel = ROUND(view.origin() * device_scale_factor) + // + // Thus in a view hierarchy, the offset between two views, view_i and view_j, + // is calculated by: + // view_offset_ij_pixel = SUM [view_origin_pixel.OffsetFromOrigin()] + // {For all views along the path from view_i to view_j} + // + // But the offset between the two layers, the layer in view_i and the layer in + // view_j, is computed by + // view_offset_ij_dip = SUM [view.origin().OffsetFromOrigin()] + // {For all views along the path from view_i to view_j} + // + // layer_offset_ij_pixel = ROUND (view_offset_ij_dip * device_scale_factor) + // + // Due to this difference in the logic for computation of offset, the values + // view_offset_ij_pixel and layer_offset_ij_pixel may not always be equal. + // They will differ by some subpixel_offset. This leads to bugs like + // crbug.com/734787. + // The subpixel offset needs to be applied to the layer to get the correct + // output during paint. + // + // This class manages the computation of subpixel offset internally when + // working with offsets. + class LayerOffsetData { + public: + LayerOffsetData(float device_scale_factor = 1.f, + const gfx::Vector2d& offset = gfx::Vector2d()) + : device_scale_factor_(device_scale_factor) { + AddOffset(offset); + } + + const gfx::Vector2d& offset() const { return offset_; } + + const gfx::Vector2dF GetSubpixelOffset() const { + // |rounded_pixel_offset_| is stored in physical pixel space. Convert it + // into DIP space before returning. + gfx::Vector2dF subpixel_offset(rounded_pixel_offset_); + subpixel_offset.Scale(1.f / device_scale_factor_); + return subpixel_offset; + } + + LayerOffsetData& operator+=(const gfx::Vector2d& offset) { + AddOffset(offset); + return *this; + } + + LayerOffsetData operator+(const gfx::Vector2d& offset) const { + LayerOffsetData offset_data(*this); + offset_data.AddOffset(offset); + return offset_data; + } + + private: + // Adds the |offset_to_parent| to the total |offset_| and updates the + // |rounded_pixel_offset_| value. + void AddOffset(const gfx::Vector2d& offset_to_parent) { + // Add the DIP |offset_to_parent| amount to the total offset. + offset_ += offset_to_parent; + + // Convert |offset_to_parent| to physical pixel coordinates. + gfx::Vector2dF fractional_pixel_offset( + offset_to_parent.x() * device_scale_factor_, + offset_to_parent.y() * device_scale_factor_); + + // Since pixels cannot be fractional, we need to round the offset to get + // the correct physical pixel coordinate. + gfx::Vector2dF integral_pixel_offset( + gfx::ToRoundedInt(fractional_pixel_offset.x()), + gfx::ToRoundedInt(fractional_pixel_offset.y())); + + // |integral_pixel_offset - fractional_pixel_offset| gives the subpixel + // offset amount for |offset_to_parent|. This is added to + // |rounded_pixel_offset_| to update the total subpixel offset. + rounded_pixel_offset_ += integral_pixel_offset - fractional_pixel_offset; + } + + // Total offset so far. This stores the offset between two nodes in the view + // hierarchy. + gfx::Vector2d offset_; + + // This stores the value such that if added to + // |offset_ * device_scale_factor| will give the correct aligned offset in + // physical pixels. + gfx::Vector2dF rounded_pixel_offset_; + + // The device scale factor at which the subpixel offset is being computed. + float device_scale_factor_; + }; + // Creation and lifetime ----------------------------------------------------- View(); @@ -424,10 +515,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, LayoutManager* GetLayoutManager() const; void SetLayoutManager(LayoutManager* layout); - // Adjust the layer's offset so that it snaps to the physical pixel boundary. - // This has no effect if the view does not have an associated layer. - void SnapLayerToPixelBoundary(); - // Attributes ---------------------------------------------------------------- // The view class name. @@ -543,7 +630,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // for View coordinates and language direction as required, allows the View // to paint itself via the various OnPaint*() event handlers and then paints // the hierarchy beneath it. - void Paint(const ui::PaintContext& parent_context); + void Paint(const PaintInfo& parent_paint_info); // The background object may be null. void SetBackground(std::unique_ptr<Background> b); @@ -1152,7 +1239,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Responsible for calling Paint() on child Views. Override to control the // order child Views are painted. - virtual void PaintChildren(const ui::PaintContext& context); + virtual void PaintChildren(const PaintInfo& info); // Override to provide rendering in any part of the View's bounds. Typically // this is the "contents" of the view. If you override this method you will @@ -1167,11 +1254,18 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Override to paint a border not specified by SetBorder(). virtual void OnPaintBorder(gfx::Canvas* canvas); + // Returns the type of scaling to be done for this View. Override this to + // change the default scaling type from |kScaleToFit|. You would want to + // override this for a view and return |kScaleToScaleFactor| in cases where + // scaling should cause no distortion. Such as in the case of an image or + // an icon. + virtual PaintInfo::ScaleType GetPaintScaleType() const; + // Accelerated painting ------------------------------------------------------ // Returns the offset from this view to the nearest ancestor with a layer. If // |layer_parent| is non-NULL it is set to the nearest ancestor with a layer. - virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer( + virtual LayerOffsetData CalculateOffsetToAncestorWithLayer( ui::Layer** layer_parent); // Updates the view's layer's parent. Called when a view is added to a view @@ -1184,11 +1278,12 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // recurses through all children. This is used when adding a layer to an // existing view to make sure all descendants that have layers are parented to // the right layer. - void MoveLayerToParent(ui::Layer* parent_layer, const gfx::Point& point); + void MoveLayerToParent(ui::Layer* parent_layer, + const LayerOffsetData& offset_data); // Called to update the bounds of any child layers within this View's // hierarchy when something happens to the hierarchy. - void UpdateChildLayerBounds(const gfx::Vector2d& offset); + void UpdateChildLayerBounds(const LayerOffsetData& offset_data); // Overridden from ui::LayerDelegate: void OnPaintLayer(const ui::PaintContext& context) override; @@ -1235,11 +1330,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Widget::ThemeChanged(). virtual void OnThemeChanged() {} - // Called when the locale has changed, overriding allows individual Views to - // update locale-dependent strings. - // To dispatch a locale changed notification, call Widget::LocaleChanged(). - virtual void OnLocaleChanged() {} - // Tooltips ------------------------------------------------------------------ // Views must invoke this when the tooltip text they are to display changes. @@ -1296,6 +1386,10 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, friend class ViewLayerTest; friend class Widget; + FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCache); + FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCacheInRTL); + FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithUnknownInvalidation); + // Painting ----------------------------------------------------------------- enum SchedulePaintType { @@ -1319,17 +1413,19 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // during painting. bool ShouldPaint() const; - // Returns the offset that should be used when constructing the paint context + // Returns the bounds that should be used when constructing the |PaintInfo| // for this view. - gfx::Vector2d GetPaintContextOffset() const; + gfx::Rect GetPaintRecordingBounds() const; // Adjusts the transform of |recorder| in advance of painting. - void SetupTransformRecorderForPainting(ui::TransformRecorder* recorder) const; + void SetupTransformRecorderForPainting( + const gfx::Vector2d& offset_from_parent, + ui::TransformRecorder* recorder) const; // Recursively calls the painting method |func| on all non-layered children, // in Z order. - void RecursivePaintHelper(void (View::*func)(const ui::PaintContext&), - const ui::PaintContext& context); + void RecursivePaintHelper(void (View::*func)(const PaintInfo&), + const PaintInfo& info); // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called // only on the root of a widget/layer. PaintDebugRects() is invoked as a @@ -1340,7 +1436,7 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // Draws a semitransparent rect to indicate the bounds of this view. // Recursively does the same for all children. Invoked only with // --draw-view-bounds-rects. - void PaintDebugRects(const ui::PaintContext& parent_context); + void PaintDebugRects(const PaintInfo& paint_info); // Tree operations ----------------------------------------------------------- @@ -1412,9 +1508,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, void AddDescendantToNotify(View* view); void RemoveDescendantToNotify(View* view); - // Sets the layer's bounds given in DIP coordinates. - void SetLayerBounds(const gfx::Rect& bounds_in_dip); - // Transformations ----------------------------------------------------------- // Returns in |transform| the transform to get from coordinates of |ancestor| @@ -1492,6 +1585,14 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // this subtree. void OrphanLayers(); + // Adjust the layer's offset so that it snaps to the physical pixel boundary. + // This has no effect if the view does not have an associated layer. + void SnapLayerToPixelBoundary(const LayerOffsetData& offset_data); + + // Sets the layer's bounds given in DIP coordinates. + void SetLayerBounds(const gfx::Size& size_in_dip, + const LayerOffsetData& layer_offset_data); + // Input --------------------------------------------------------------------- bool ProcessMousePressed(const ui::MouseEvent& event); @@ -1525,10 +1626,6 @@ class VIEWS_EXPORT View : public ui::LayerDelegate, // views in the hierarchy. void PropagateThemeChanged(); - // Used to propagate locale changed notifications from the root view to all - // views in the hierarchy. - void PropagateLocaleChanged(); - // Used to propagate device scale factor changed notifications from the root // view to all views in the hierarchy. void PropagateDeviceScaleFactorChanged(float device_scale_factor); |