Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1264 static int GetHorizontalDragThreshold(); | 1265 static int GetHorizontalDragThreshold(); |
| 1265 static int GetVerticalDragThreshold(); | 1266 static int GetVerticalDragThreshold(); |
| 1266 | 1267 |
| 1267 // NativeTheme --------------------------------------------------------------- | 1268 // NativeTheme --------------------------------------------------------------- |
| 1268 | 1269 |
| 1269 // Invoked when the NativeTheme associated with this View changes, including | 1270 // Invoked when the NativeTheme associated with this View changes, including |
| 1270 // when one first becomes available (after the view is added to a widget | 1271 // when one first becomes available (after the view is added to a widget |
| 1271 // hierarchy). | 1272 // hierarchy). |
| 1272 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) {} | 1273 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) {} |
| 1273 | 1274 |
| 1275 // Pixel Canvas -------------------------------------------------------------- | |
| 1276 | |
| 1277 // Returns the type of scaling to be done for this View. Values should be from | |
| 1278 // PaintInfo::ScaleType. | |
|
sky
2017/07/26 22:12:12
Remove second sentence as this is obvious given th
malaykeshav
2017/07/28 01:24:38
Done
| |
| 1279 virtual PaintInfo::ScaleType GetPaintScaleType() const; | |
|
sky
2017/07/26 22:12:12
Move this up with the other painting functions. Sa
sky
2017/07/26 22:12:12
Are we really going to have different scale types
malaykeshav
2017/07/28 01:24:38
All except the ones that don't want any distortion
malaykeshav
2017/07/28 01:24:38
Done.
| |
| 1280 | |
| 1274 // Debugging ----------------------------------------------------------------- | 1281 // Debugging ----------------------------------------------------------------- |
| 1275 | 1282 |
| 1276 #if !defined(NDEBUG) | 1283 #if !defined(NDEBUG) |
| 1277 // Returns string containing a graph of the views hierarchy in graphViz DOT | 1284 // Returns string containing a graph of the views hierarchy in graphViz DOT |
| 1278 // language (http://graphviz.org/). Can be called within debugger and save | 1285 // language (http://graphviz.org/). Can be called within debugger and save |
| 1279 // to a file to compile/view. | 1286 // to a file to compile/view. |
| 1280 // Note: Assumes initial call made with first = true. | 1287 // Note: Assumes initial call made with first = true. |
| 1281 virtual std::string PrintViewGraph(bool first); | 1288 virtual std::string PrintViewGraph(bool first); |
| 1282 | 1289 |
| 1283 // Some classes may own an object which contains the children to displayed in | 1290 // Some classes may own an object which contains the children to displayed in |
| 1284 // the views hierarchy. The above function gives the class the flexibility to | 1291 // the views hierarchy. The above function gives the class the flexibility to |
| 1285 // decide which object should be used to obtain the children, but this | 1292 // decide which object should be used to obtain the children, but this |
| 1286 // function makes the decision explicit. | 1293 // function makes the decision explicit. |
| 1287 std::string DoPrintViewGraph(bool first, View* view_with_children); | 1294 std::string DoPrintViewGraph(bool first, View* view_with_children); |
| 1288 #endif | 1295 #endif |
| 1289 | 1296 |
| 1290 private: | 1297 private: |
| 1291 friend class internal::PreEventDispatchHandler; | 1298 friend class internal::PreEventDispatchHandler; |
| 1292 friend class internal::PostEventDispatchHandler; | 1299 friend class internal::PostEventDispatchHandler; |
| 1293 friend class internal::RootView; | 1300 friend class internal::RootView; |
| 1294 friend class internal::ScopedChildrenLock; | 1301 friend class internal::ScopedChildrenLock; |
| 1295 friend class FocusManager; | 1302 friend class FocusManager; |
| 1296 friend class ViewLayerTest; | 1303 friend class ViewLayerTest; |
| 1297 friend class Widget; | 1304 friend class Widget; |
| 1298 | 1305 |
| 1306 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCache); | |
| 1307 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCacheInRTL); | |
| 1308 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithUnknownInvalidation); | |
| 1309 | |
| 1299 // Painting ----------------------------------------------------------------- | 1310 // Painting ----------------------------------------------------------------- |
| 1300 | 1311 |
| 1301 enum SchedulePaintType { | 1312 enum SchedulePaintType { |
| 1302 // Indicates the size is the same (only the origin changed). | 1313 // Indicates the size is the same (only the origin changed). |
| 1303 SCHEDULE_PAINT_SIZE_SAME, | 1314 SCHEDULE_PAINT_SIZE_SAME, |
| 1304 | 1315 |
| 1305 // Indicates the size changed (and possibly the origin). | 1316 // Indicates the size changed (and possibly the origin). |
| 1306 SCHEDULE_PAINT_SIZE_CHANGED | 1317 SCHEDULE_PAINT_SIZE_CHANGED |
| 1307 }; | 1318 }; |
| 1308 | 1319 |
| 1309 // Invoked before and after the bounds change to schedule painting the old and | 1320 // Invoked before and after the bounds change to schedule painting the old and |
| 1310 // new bounds. | 1321 // new bounds. |
| 1311 void SchedulePaintBoundsChanged(SchedulePaintType type); | 1322 void SchedulePaintBoundsChanged(SchedulePaintType type); |
| 1312 | 1323 |
| 1313 // Schedules a paint on the parent View if it exists. | 1324 // Schedules a paint on the parent View if it exists. |
| 1314 void SchedulePaintOnParent(); | 1325 void SchedulePaintOnParent(); |
| 1315 | 1326 |
| 1316 // Returns whether this view is eligible for painting, i.e. is visible and | 1327 // 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 | 1328 // 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 | 1329 // check ancestors recursively; rather, it's used to prune subtrees of views |
| 1319 // during painting. | 1330 // during painting. |
| 1320 bool ShouldPaint() const; | 1331 bool ShouldPaint() const; |
| 1321 | 1332 |
| 1322 // Returns the offset that should be used when constructing the paint context | 1333 // Returns the bounds that should be used when constructing the |PaintInfo| |
| 1323 // for this view. | 1334 // for this view. |
| 1324 gfx::Vector2d GetPaintContextOffset() const; | 1335 gfx::Rect GetPaintRecordingBounds() const; |
| 1325 | 1336 |
| 1326 // Adjusts the transform of |recorder| in advance of painting. | 1337 // Adjusts the transform of |recorder| in advance of painting. |
| 1327 void SetupTransformRecorderForPainting(ui::TransformRecorder* recorder) const; | 1338 void SetupTransformRecorderForPainting( |
| 1339 ui::TransformRecorder* recorder, | |
| 1340 const gfx::Vector2d& offset_from_parent) const; | |
| 1328 | 1341 |
| 1329 // Recursively calls the painting method |func| on all non-layered children, | 1342 // Recursively calls the painting method |func| on all non-layered children, |
| 1330 // in Z order. | 1343 // in Z order. |
| 1331 void RecursivePaintHelper(void (View::*func)(const ui::PaintContext&), | 1344 void RecursivePaintHelper(void (View::*func)(const PaintInfo&), |
| 1332 const ui::PaintContext& context); | 1345 const PaintInfo& info); |
| 1333 | 1346 |
| 1334 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called | 1347 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called |
| 1335 // only on the root of a widget/layer. PaintDebugRects() is invoked as a | 1348 // 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 | 1349 // separate pass, instead of being rolled into Paint(), so that siblings will |
| 1337 // not obscure debug rects. | 1350 // not obscure debug rects. |
| 1338 void PaintFromPaintRoot(const ui::PaintContext& parent_context); | 1351 void PaintFromPaintRoot(const ui::PaintContext& parent_context); |
| 1339 | 1352 |
| 1340 // Draws a semitransparent rect to indicate the bounds of this view. | 1353 // Draws a semitransparent rect to indicate the bounds of this view. |
| 1341 // Recursively does the same for all children. Invoked only with | 1354 // Recursively does the same for all children. Invoked only with |
| 1342 // --draw-view-bounds-rects. | 1355 // --draw-view-bounds-rects. |
| 1343 void PaintDebugRects(const ui::PaintContext& parent_context); | 1356 void PaintDebugRects(const PaintInfo& paint_info); |
| 1344 | 1357 |
| 1345 // Tree operations ----------------------------------------------------------- | 1358 // Tree operations ----------------------------------------------------------- |
| 1346 | 1359 |
| 1347 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, | 1360 // 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 | 1361 // 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 | 1362 // 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 | 1363 // |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 | 1364 // 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 | 1365 // 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. | 1366 // that |view| is going to be added to after the remove completes. |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 // Observers ------------------------------------------------------------- | 1725 // Observers ------------------------------------------------------------- |
| 1713 | 1726 |
| 1714 base::ObserverList<ViewObserver> observers_; | 1727 base::ObserverList<ViewObserver> observers_; |
| 1715 | 1728 |
| 1716 DISALLOW_COPY_AND_ASSIGN(View); | 1729 DISALLOW_COPY_AND_ASSIGN(View); |
| 1717 }; | 1730 }; |
| 1718 | 1731 |
| 1719 } // namespace views | 1732 } // namespace views |
| 1720 | 1733 |
| 1721 #endif // UI_VIEWS_VIEW_H_ | 1734 #endif // UI_VIEWS_VIEW_H_ |
| OLD | NEW |