Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: ui/views/view.h

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: Sync With ToT Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/paint_info_unittest.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef UI_VIEWS_VIEW_H_ 5 #ifndef UI_VIEWS_VIEW_H_
6 #define UI_VIEWS_VIEW_H_ 6 #define UI_VIEWS_VIEW_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 19 matching lines...) Expand all
30 #include "ui/compositor/layer_owner.h" 30 #include "ui/compositor/layer_owner.h"
31 #include "ui/compositor/paint_cache.h" 31 #include "ui/compositor/paint_cache.h"
32 #include "ui/events/event.h" 32 #include "ui/events/event.h"
33 #include "ui/events/event_target.h" 33 #include "ui/events/event_target.h"
34 #include "ui/gfx/geometry/insets.h" 34 #include "ui/gfx/geometry/insets.h"
35 #include "ui/gfx/geometry/point.h" 35 #include "ui/gfx/geometry/point.h"
36 #include "ui/gfx/geometry/rect.h" 36 #include "ui/gfx/geometry/rect.h"
37 #include "ui/gfx/geometry/vector2d.h" 37 #include "ui/gfx/geometry/vector2d.h"
38 #include "ui/gfx/native_widget_types.h" 38 #include "ui/gfx/native_widget_types.h"
39 #include "ui/gfx/path.h" 39 #include "ui/gfx/path.h"
40 #include "ui/views/paint_info.h"
40 #include "ui/views/view_targeter.h" 41 #include "ui/views/view_targeter.h"
41 #include "ui/views/views_export.h" 42 #include "ui/views/views_export.h"
42 43
43 #if defined(OS_WIN) 44 #if defined(OS_WIN)
44 #include "base/win/scoped_comptr.h" 45 #include "base/win/scoped_comptr.h"
45 #endif 46 #endif
46 47
47 using ui::OSExchangeData; 48 using ui::OSExchangeData;
48 49
49 namespace gfx { 50 namespace gfx {
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // transformations are applied to it to convert it into the parent coordinate 537 // transformations are applied to it to convert it into the parent coordinate
537 // system before propagating SchedulePaint up the view hierarchy. 538 // system before propagating SchedulePaint up the view hierarchy.
538 // TODO(beng): Make protected. 539 // TODO(beng): Make protected.
539 void SchedulePaint(); 540 void SchedulePaint();
540 virtual void SchedulePaintInRect(const gfx::Rect& r); 541 virtual void SchedulePaintInRect(const gfx::Rect& r);
541 542
542 // Called by the framework to paint a View. Performs translation and clipping 543 // Called by the framework to paint a View. Performs translation and clipping
543 // for View coordinates and language direction as required, allows the View 544 // for View coordinates and language direction as required, allows the View
544 // to paint itself via the various OnPaint*() event handlers and then paints 545 // to paint itself via the various OnPaint*() event handlers and then paints
545 // the hierarchy beneath it. 546 // the hierarchy beneath it.
546 void Paint(const ui::PaintContext& parent_context); 547 void Paint(const PaintInfo& parent_paint_info);
547 548
548 // The background object may be null. 549 // The background object may be null.
549 void SetBackground(std::unique_ptr<Background> b); 550 void SetBackground(std::unique_ptr<Background> b);
550 const Background* background() const { return background_.get(); } 551 const Background* background() const { return background_.get(); }
551 Background* background() { return background_.get(); } 552 Background* background() { return background_.get(); }
552 553
553 // The border object may be null. 554 // The border object may be null.
554 virtual void SetBorder(std::unique_ptr<Border> b); 555 virtual void SetBorder(std::unique_ptr<Border> b);
555 const Border* border() const { return border_.get(); } 556 const Border* border() const { return border_.get(); }
556 Border* border() { return border_.get(); } 557 Border* border() { return border_.get(); }
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 virtual void AddedToWidget(); 1146 virtual void AddedToWidget();
1146 1147
1147 // This method is invoked for a view when it is removed from a hierarchy with 1148 // This method is invoked for a view when it is removed from a hierarchy with
1148 // a widget or moved to a different widget. 1149 // a widget or moved to a different widget.
1149 virtual void RemovedFromWidget(); 1150 virtual void RemovedFromWidget();
1150 1151
1151 // Painting ------------------------------------------------------------------ 1152 // Painting ------------------------------------------------------------------
1152 1153
1153 // Responsible for calling Paint() on child Views. Override to control the 1154 // Responsible for calling Paint() on child Views. Override to control the
1154 // order child Views are painted. 1155 // order child Views are painted.
1155 virtual void PaintChildren(const ui::PaintContext& context); 1156 virtual void PaintChildren(const PaintInfo& info);
1156 1157
1157 // Override to provide rendering in any part of the View's bounds. Typically 1158 // Override to provide rendering in any part of the View's bounds. Typically
1158 // this is the "contents" of the view. If you override this method you will 1159 // this is the "contents" of the view. If you override this method you will
1159 // have to call the subsequent OnPaint*() methods manually. 1160 // have to call the subsequent OnPaint*() methods manually.
1160 virtual void OnPaint(gfx::Canvas* canvas); 1161 virtual void OnPaint(gfx::Canvas* canvas);
1161 1162
1162 // Override to paint a background before any content is drawn. Typically this 1163 // Override to paint a background before any content is drawn. Typically this
1163 // is done if you are satisfied with a default OnPaint handler but wish to 1164 // is done if you are satisfied with a default OnPaint handler but wish to
1164 // supply a different background. 1165 // supply a different background.
1165 virtual void OnPaintBackground(gfx::Canvas* canvas); 1166 virtual void OnPaintBackground(gfx::Canvas* canvas);
1166 1167
1167 // Override to paint a border not specified by SetBorder(). 1168 // Override to paint a border not specified by SetBorder().
1168 virtual void OnPaintBorder(gfx::Canvas* canvas); 1169 virtual void OnPaintBorder(gfx::Canvas* canvas);
1169 1170
1171 // Returns the type of scaling to be done for this View.
sky 2017/08/01 15:10:24 You still haven't outlined when and why this shoul
malaykeshav 2017/08/01 19:31:01 Done
1172 virtual PaintInfo::ScaleType GetPaintScaleType() const;
1173
1170 // Accelerated painting ------------------------------------------------------ 1174 // Accelerated painting ------------------------------------------------------
1171 1175
1172 // Returns the offset from this view to the nearest ancestor with a layer. If 1176 // Returns the offset from this view to the nearest ancestor with a layer. If
1173 // |layer_parent| is non-NULL it is set to the nearest ancestor with a layer. 1177 // |layer_parent| is non-NULL it is set to the nearest ancestor with a layer.
1174 virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer( 1178 virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer(
1175 ui::Layer** layer_parent); 1179 ui::Layer** layer_parent);
1176 1180
1177 // Updates the view's layer's parent. Called when a view is added to a view 1181 // Updates the view's layer's parent. Called when a view is added to a view
1178 // hierarchy, responsible for parenting the view's layer to the enclosing 1182 // hierarchy, responsible for parenting the view's layer to the enclosing
1179 // layer in the hierarchy. 1183 // layer in the hierarchy.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 1293
1290 private: 1294 private:
1291 friend class internal::PreEventDispatchHandler; 1295 friend class internal::PreEventDispatchHandler;
1292 friend class internal::PostEventDispatchHandler; 1296 friend class internal::PostEventDispatchHandler;
1293 friend class internal::RootView; 1297 friend class internal::RootView;
1294 friend class internal::ScopedChildrenLock; 1298 friend class internal::ScopedChildrenLock;
1295 friend class FocusManager; 1299 friend class FocusManager;
1296 friend class ViewLayerTest; 1300 friend class ViewLayerTest;
1297 friend class Widget; 1301 friend class Widget;
1298 1302
1303 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCache);
1304 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCacheInRTL);
1305 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithUnknownInvalidation);
1306
1299 // Painting ----------------------------------------------------------------- 1307 // Painting -----------------------------------------------------------------
1300 1308
1301 enum SchedulePaintType { 1309 enum SchedulePaintType {
1302 // Indicates the size is the same (only the origin changed). 1310 // Indicates the size is the same (only the origin changed).
1303 SCHEDULE_PAINT_SIZE_SAME, 1311 SCHEDULE_PAINT_SIZE_SAME,
1304 1312
1305 // Indicates the size changed (and possibly the origin). 1313 // Indicates the size changed (and possibly the origin).
1306 SCHEDULE_PAINT_SIZE_CHANGED 1314 SCHEDULE_PAINT_SIZE_CHANGED
1307 }; 1315 };
1308 1316
1309 // Invoked before and after the bounds change to schedule painting the old and 1317 // Invoked before and after the bounds change to schedule painting the old and
1310 // new bounds. 1318 // new bounds.
1311 void SchedulePaintBoundsChanged(SchedulePaintType type); 1319 void SchedulePaintBoundsChanged(SchedulePaintType type);
1312 1320
1313 // Schedules a paint on the parent View if it exists. 1321 // Schedules a paint on the parent View if it exists.
1314 void SchedulePaintOnParent(); 1322 void SchedulePaintOnParent();
1315 1323
1316 // Returns whether this view is eligible for painting, i.e. is visible and 1324 // Returns whether this view is eligible for painting, i.e. is visible and
1317 // nonempty. Note that this does not behave like IsDrawn(), since it doesn't 1325 // nonempty. Note that this does not behave like IsDrawn(), since it doesn't
1318 // check ancestors recursively; rather, it's used to prune subtrees of views 1326 // check ancestors recursively; rather, it's used to prune subtrees of views
1319 // during painting. 1327 // during painting.
1320 bool ShouldPaint() const; 1328 bool ShouldPaint() const;
1321 1329
1322 // Returns the offset that should be used when constructing the paint context 1330 // Returns the bounds that should be used when constructing the |PaintInfo|
1323 // for this view. 1331 // for this view.
1324 gfx::Vector2d GetPaintContextOffset() const; 1332 gfx::Rect GetPaintRecordingBounds() const;
1325 1333
1326 // Adjusts the transform of |recorder| in advance of painting. 1334 // Adjusts the transform of |recorder| in advance of painting.
1327 void SetupTransformRecorderForPainting(ui::TransformRecorder* recorder) const; 1335 void SetupTransformRecorderForPainting(
1336 const gfx::Vector2d& offset_from_parent,
1337 ui::TransformRecorder* recorder) const;
1328 1338
1329 // Recursively calls the painting method |func| on all non-layered children, 1339 // Recursively calls the painting method |func| on all non-layered children,
1330 // in Z order. 1340 // in Z order.
1331 void RecursivePaintHelper(void (View::*func)(const ui::PaintContext&), 1341 void RecursivePaintHelper(void (View::*func)(const PaintInfo&),
1332 const ui::PaintContext& context); 1342 const PaintInfo& info);
1333 1343
1334 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called 1344 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called
1335 // only on the root of a widget/layer. PaintDebugRects() is invoked as a 1345 // only on the root of a widget/layer. PaintDebugRects() is invoked as a
1336 // separate pass, instead of being rolled into Paint(), so that siblings will 1346 // separate pass, instead of being rolled into Paint(), so that siblings will
1337 // not obscure debug rects. 1347 // not obscure debug rects.
1338 void PaintFromPaintRoot(const ui::PaintContext& parent_context); 1348 void PaintFromPaintRoot(const ui::PaintContext& parent_context);
1339 1349
1340 // Draws a semitransparent rect to indicate the bounds of this view. 1350 // Draws a semitransparent rect to indicate the bounds of this view.
1341 // Recursively does the same for all children. Invoked only with 1351 // Recursively does the same for all children. Invoked only with
1342 // --draw-view-bounds-rects. 1352 // --draw-view-bounds-rects.
1343 void PaintDebugRects(const ui::PaintContext& parent_context); 1353 void PaintDebugRects(const PaintInfo& paint_info);
1344 1354
1345 // Tree operations ----------------------------------------------------------- 1355 // Tree operations -----------------------------------------------------------
1346 1356
1347 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, 1357 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1348 // the next and previous focusable views of views pointing to this view are 1358 // the next and previous focusable views of views pointing to this view are
1349 // updated. If |update_tool_tip| is true, the tooltip is updated. If 1359 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1350 // |delete_removed_view| is true, the view is also deleted (if it is parent 1360 // |delete_removed_view| is true, the view is also deleted (if it is parent
1351 // owned). If |new_parent| is not NULL, the remove is the result of 1361 // owned). If |new_parent| is not NULL, the remove is the result of
1352 // AddChildView() to a new parent. For this case, |new_parent| is the View 1362 // AddChildView() to a new parent. For this case, |new_parent| is the View
1353 // that |view| is going to be added to after the remove completes. 1363 // that |view| is going to be added to after the remove completes.
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 // Observers ------------------------------------------------------------- 1722 // Observers -------------------------------------------------------------
1713 1723
1714 base::ObserverList<ViewObserver> observers_; 1724 base::ObserverList<ViewObserver> observers_;
1715 1725
1716 DISALLOW_COPY_AND_ASSIGN(View); 1726 DISALLOW_COPY_AND_ASSIGN(View);
1717 }; 1727 };
1718 1728
1719 } // namespace views 1729 } // namespace views
1720 1730
1721 #endif // UI_VIEWS_VIEW_H_ 1731 #endif // UI_VIEWS_VIEW_H_
OLDNEW
« no previous file with comments | « ui/views/paint_info_unittest.cc ('k') | ui/views/view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698