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

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. Override this to
1172 // change the default scaling type from |kScaleToFit|. You would want to
1173 // override this for a view and return |kScaleToScaleFactor| in cases where
1174 // scaling should cause no distortion. Such as in the case of an image or
1175 // an icon.
1176 virtual PaintInfo::ScaleType GetPaintScaleType() const;
1177
1170 // Accelerated painting ------------------------------------------------------ 1178 // Accelerated painting ------------------------------------------------------
1171 1179
1172 // Returns the offset from this view to the nearest ancestor with a layer. If 1180 // 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. 1181 // |layer_parent| is non-NULL it is set to the nearest ancestor with a layer.
1174 virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer( 1182 virtual gfx::Vector2d CalculateOffsetToAncestorWithLayer(
1175 ui::Layer** layer_parent); 1183 ui::Layer** layer_parent);
1176 1184
1177 // Updates the view's layer's parent. Called when a view is added to a view 1185 // 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 1186 // hierarchy, responsible for parenting the view's layer to the enclosing
1179 // layer in the hierarchy. 1187 // layer in the hierarchy.
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1284 1292
1285 private: 1293 private:
1286 friend class internal::PreEventDispatchHandler; 1294 friend class internal::PreEventDispatchHandler;
1287 friend class internal::PostEventDispatchHandler; 1295 friend class internal::PostEventDispatchHandler;
1288 friend class internal::RootView; 1296 friend class internal::RootView;
1289 friend class internal::ScopedChildrenLock; 1297 friend class internal::ScopedChildrenLock;
1290 friend class FocusManager; 1298 friend class FocusManager;
1291 friend class ViewLayerTest; 1299 friend class ViewLayerTest;
1292 friend class Widget; 1300 friend class Widget;
1293 1301
1302 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCache);
1303 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithMovedViewUsesCacheInRTL);
1304 FRIEND_TEST_ALL_PREFIXES(ViewTest, PaintWithUnknownInvalidation);
1305
1294 // Painting ----------------------------------------------------------------- 1306 // Painting -----------------------------------------------------------------
1295 1307
1296 enum SchedulePaintType { 1308 enum SchedulePaintType {
1297 // Indicates the size is the same (only the origin changed). 1309 // Indicates the size is the same (only the origin changed).
1298 SCHEDULE_PAINT_SIZE_SAME, 1310 SCHEDULE_PAINT_SIZE_SAME,
1299 1311
1300 // Indicates the size changed (and possibly the origin). 1312 // Indicates the size changed (and possibly the origin).
1301 SCHEDULE_PAINT_SIZE_CHANGED 1313 SCHEDULE_PAINT_SIZE_CHANGED
1302 }; 1314 };
1303 1315
1304 // Invoked before and after the bounds change to schedule painting the old and 1316 // Invoked before and after the bounds change to schedule painting the old and
1305 // new bounds. 1317 // new bounds.
1306 void SchedulePaintBoundsChanged(SchedulePaintType type); 1318 void SchedulePaintBoundsChanged(SchedulePaintType type);
1307 1319
1308 // Schedules a paint on the parent View if it exists. 1320 // Schedules a paint on the parent View if it exists.
1309 void SchedulePaintOnParent(); 1321 void SchedulePaintOnParent();
1310 1322
1311 // Returns whether this view is eligible for painting, i.e. is visible and 1323 // Returns whether this view is eligible for painting, i.e. is visible and
1312 // nonempty. Note that this does not behave like IsDrawn(), since it doesn't 1324 // nonempty. Note that this does not behave like IsDrawn(), since it doesn't
1313 // check ancestors recursively; rather, it's used to prune subtrees of views 1325 // check ancestors recursively; rather, it's used to prune subtrees of views
1314 // during painting. 1326 // during painting.
1315 bool ShouldPaint() const; 1327 bool ShouldPaint() const;
1316 1328
1317 // Returns the offset that should be used when constructing the paint context 1329 // Returns the bounds that should be used when constructing the |PaintInfo|
1318 // for this view. 1330 // for this view.
1319 gfx::Vector2d GetPaintContextOffset() const; 1331 gfx::Rect GetPaintRecordingBounds() const;
1320 1332
1321 // Adjusts the transform of |recorder| in advance of painting. 1333 // Adjusts the transform of |recorder| in advance of painting.
1322 void SetupTransformRecorderForPainting(ui::TransformRecorder* recorder) const; 1334 void SetupTransformRecorderForPainting(
1335 const gfx::Vector2d& offset_from_parent,
1336 ui::TransformRecorder* recorder) const;
1323 1337
1324 // Recursively calls the painting method |func| on all non-layered children, 1338 // Recursively calls the painting method |func| on all non-layered children,
1325 // in Z order. 1339 // in Z order.
1326 void RecursivePaintHelper(void (View::*func)(const ui::PaintContext&), 1340 void RecursivePaintHelper(void (View::*func)(const PaintInfo&),
1327 const ui::PaintContext& context); 1341 const PaintInfo& info);
1328 1342
1329 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called 1343 // Invokes Paint() and, if necessary, PaintDebugRects(). Should be called
1330 // only on the root of a widget/layer. PaintDebugRects() is invoked as a 1344 // only on the root of a widget/layer. PaintDebugRects() is invoked as a
1331 // separate pass, instead of being rolled into Paint(), so that siblings will 1345 // separate pass, instead of being rolled into Paint(), so that siblings will
1332 // not obscure debug rects. 1346 // not obscure debug rects.
1333 void PaintFromPaintRoot(const ui::PaintContext& parent_context); 1347 void PaintFromPaintRoot(const ui::PaintContext& parent_context);
1334 1348
1335 // Draws a semitransparent rect to indicate the bounds of this view. 1349 // Draws a semitransparent rect to indicate the bounds of this view.
1336 // Recursively does the same for all children. Invoked only with 1350 // Recursively does the same for all children. Invoked only with
1337 // --draw-view-bounds-rects. 1351 // --draw-view-bounds-rects.
1338 void PaintDebugRects(const ui::PaintContext& parent_context); 1352 void PaintDebugRects(const PaintInfo& paint_info);
1339 1353
1340 // Tree operations ----------------------------------------------------------- 1354 // Tree operations -----------------------------------------------------------
1341 1355
1342 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true, 1356 // Removes |view| from the hierarchy tree. If |update_focus_cycle| is true,
1343 // the next and previous focusable views of views pointing to this view are 1357 // the next and previous focusable views of views pointing to this view are
1344 // updated. If |update_tool_tip| is true, the tooltip is updated. If 1358 // updated. If |update_tool_tip| is true, the tooltip is updated. If
1345 // |delete_removed_view| is true, the view is also deleted (if it is parent 1359 // |delete_removed_view| is true, the view is also deleted (if it is parent
1346 // owned). If |new_parent| is not NULL, the remove is the result of 1360 // owned). If |new_parent| is not NULL, the remove is the result of
1347 // AddChildView() to a new parent. For this case, |new_parent| is the View 1361 // AddChildView() to a new parent. For this case, |new_parent| is the View
1348 // that |view| is going to be added to after the remove completes. 1362 // that |view| is going to be added to after the remove completes.
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1703 // Observers ------------------------------------------------------------- 1717 // Observers -------------------------------------------------------------
1704 1718
1705 base::ObserverList<ViewObserver> observers_; 1719 base::ObserverList<ViewObserver> observers_;
1706 1720
1707 DISALLOW_COPY_AND_ASSIGN(View); 1721 DISALLOW_COPY_AND_ASSIGN(View);
1708 }; 1722 };
1709 1723
1710 } // namespace views 1724 } // namespace views
1711 1725
1712 #endif // UI_VIEWS_VIEW_H_ 1726 #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