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

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

Issue 2500623002: Add ViewObserver to View for view updates (Closed)
Patch Set: Ensure single call of OnViewHierarchyChanged Created 4 years, 1 month 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
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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 30 matching lines...) Expand all
41 #include "ui/gfx/interpolated_transform.h" 41 #include "ui/gfx/interpolated_transform.h"
42 #include "ui/gfx/path.h" 42 #include "ui/gfx/path.h"
43 #include "ui/gfx/scoped_canvas.h" 43 #include "ui/gfx/scoped_canvas.h"
44 #include "ui/gfx/skia_util.h" 44 #include "ui/gfx/skia_util.h"
45 #include "ui/gfx/transform.h" 45 #include "ui/gfx/transform.h"
46 #include "ui/native_theme/native_theme.h" 46 #include "ui/native_theme/native_theme.h"
47 #include "ui/views/accessibility/native_view_accessibility.h" 47 #include "ui/views/accessibility/native_view_accessibility.h"
48 #include "ui/views/background.h" 48 #include "ui/views/background.h"
49 #include "ui/views/border.h" 49 #include "ui/views/border.h"
50 #include "ui/views/context_menu_controller.h" 50 #include "ui/views/context_menu_controller.h"
51 #include "ui/views/devtools_observer.h"
51 #include "ui/views/drag_controller.h" 52 #include "ui/views/drag_controller.h"
52 #include "ui/views/focus/view_storage.h" 53 #include "ui/views/focus/view_storage.h"
53 #include "ui/views/layout/layout_manager.h" 54 #include "ui/views/layout/layout_manager.h"
54 #include "ui/views/views_delegate.h" 55 #include "ui/views/views_delegate.h"
55 #include "ui/views/widget/native_widget_private.h" 56 #include "ui/views/widget/native_widget_private.h"
56 #include "ui/views/widget/root_view.h" 57 #include "ui/views/widget/root_view.h"
57 #include "ui/views/widget/tooltip_manager.h" 58 #include "ui/views/widget/tooltip_manager.h"
58 #include "ui/views/widget/widget.h" 59 #include "ui/views/widget/widget.h"
59 60
60 #if defined(OS_WIN) 61 #if defined(OS_WIN)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 snap_layer_to_pixel_boundary_(false), 112 snap_layer_to_pixel_boundary_(false),
112 flip_canvas_on_paint_for_rtl_ui_(false), 113 flip_canvas_on_paint_for_rtl_ui_(false),
113 paint_to_layer_(false), 114 paint_to_layer_(false),
114 accelerator_focus_manager_(NULL), 115 accelerator_focus_manager_(NULL),
115 registered_accelerator_count_(0), 116 registered_accelerator_count_(0),
116 next_focusable_view_(NULL), 117 next_focusable_view_(NULL),
117 previous_focusable_view_(NULL), 118 previous_focusable_view_(NULL),
118 focus_behavior_(FocusBehavior::NEVER), 119 focus_behavior_(FocusBehavior::NEVER),
119 context_menu_controller_(NULL), 120 context_menu_controller_(NULL),
120 drag_controller_(NULL), 121 drag_controller_(NULL),
121 native_view_accessibility_(NULL) { 122 native_view_accessibility_(NULL),
123 devtools_observer_(nullptr) {
122 SetTargetHandler(this); 124 SetTargetHandler(this);
123 } 125 }
124 126
125 View::~View() { 127 View::~View() {
126 if (parent_) 128 if (parent_)
127 parent_->RemoveChildView(this); 129 parent_->RemoveChildView(this);
128 130
129 ViewStorage::GetInstance()->ViewRemoved(this); 131 ViewStorage::GetInstance()->ViewRemoved(this);
130 132
131 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) { 133 for (Views::const_iterator i(children_.begin()); i != children_.end(); ++i) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 215
214 if (widget) { 216 if (widget) {
215 RegisterChildrenForVisibleBoundsNotification(view); 217 RegisterChildrenForVisibleBoundsNotification(view);
216 218
217 if (view->visible()) 219 if (view->visible())
218 view->SchedulePaint(); 220 view->SchedulePaint();
219 } 221 }
220 222
221 if (layout_manager_.get()) 223 if (layout_manager_.get())
222 layout_manager_->ViewAdded(this, view); 224 layout_manager_->ViewAdded(this, view);
225
226 if (devtools_observer_)
227 devtools_observer_->OnViewHierarchyChanged(view, nullptr, this);
223 } 228 }
224 229
225 void View::ReorderChildView(View* view, int index) { 230 void View::ReorderChildView(View* view, int index) {
226 DCHECK_EQ(view->parent_, this); 231 DCHECK_EQ(view->parent_, this);
227 if (index < 0) 232 if (index < 0)
228 index = child_count() - 1; 233 index = child_count() - 1;
229 else if (index >= child_count()) 234 else if (index >= child_count())
230 return; 235 return;
231 if (children_[index] == view) 236 if (children_[index] == view)
232 return; 237 return;
233 238
234 const Views::iterator i(std::find(children_.begin(), children_.end(), view)); 239 const Views::iterator i(std::find(children_.begin(), children_.end(), view));
235 DCHECK(i != children_.end()); 240 DCHECK(i != children_.end());
236 children_.erase(i); 241 children_.erase(i);
237 242
238 // Unlink the view first 243 // Unlink the view first
239 View* next_focusable = view->next_focusable_view_; 244 View* next_focusable = view->next_focusable_view_;
240 View* prev_focusable = view->previous_focusable_view_; 245 View* prev_focusable = view->previous_focusable_view_;
241 if (prev_focusable) 246 if (prev_focusable)
242 prev_focusable->next_focusable_view_ = next_focusable; 247 prev_focusable->next_focusable_view_ = next_focusable;
243 if (next_focusable) 248 if (next_focusable)
244 next_focusable->previous_focusable_view_ = prev_focusable; 249 next_focusable->previous_focusable_view_ = prev_focusable;
245 250
251 if (devtools_observer_)
252 devtools_observer_->OnChildViewReordered(view, index);
253
246 // Add it in the specified index now. 254 // Add it in the specified index now.
247 InitFocusSiblings(view, index); 255 InitFocusSiblings(view, index);
248 children_.insert(children_.begin() + index, view); 256 children_.insert(children_.begin() + index, view);
249 257
250 ReorderLayers(); 258 ReorderLayers();
251 } 259 }
252 260
253 void View::RemoveChildView(View* view) { 261 void View::RemoveChildView(View* view) {
254 DoRemoveChildView(view, true, true, false, NULL); 262 DoRemoveChildView(view, true, true, false, NULL);
255 } 263 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return; 296 return;
289 } 297 }
290 298
291 if (visible_) { 299 if (visible_) {
292 // Paint where the view is currently. 300 // Paint where the view is currently.
293 SchedulePaintBoundsChanged( 301 SchedulePaintBoundsChanged(
294 bounds_.size() == bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : 302 bounds_.size() == bounds.size() ? SCHEDULE_PAINT_SIZE_SAME :
295 SCHEDULE_PAINT_SIZE_CHANGED); 303 SCHEDULE_PAINT_SIZE_CHANGED);
296 } 304 }
297 305
306 if (devtools_observer_)
307 devtools_observer_->OnViewBoundsChanged(this, bounds);
308
298 gfx::Rect prev = bounds_; 309 gfx::Rect prev = bounds_;
299 bounds_ = bounds; 310 bounds_ = bounds;
300 BoundsChanged(prev); 311 BoundsChanged(prev);
301 } 312 }
302 313
303 void View::SetSize(const gfx::Size& size) { 314 void View::SetSize(const gfx::Size& size) {
304 SetBounds(x(), y(), size.width(), size.height()); 315 SetBounds(x(), y(), size.width(), size.height());
305 } 316 }
306 317
307 void View::SetPosition(const gfx::Point& position) { 318 void View::SetPosition(const gfx::Point& position) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 440 }
430 441
431 bool View::IsDrawn() const { 442 bool View::IsDrawn() const {
432 return visible_ && parent_ ? parent_->IsDrawn() : false; 443 return visible_ && parent_ ? parent_->IsDrawn() : false;
433 } 444 }
434 445
435 void View::SetEnabled(bool enabled) { 446 void View::SetEnabled(bool enabled) {
436 if (enabled != enabled_) { 447 if (enabled != enabled_) {
437 enabled_ = enabled; 448 enabled_ = enabled;
438 AdvanceFocusIfNecessary(); 449 AdvanceFocusIfNecessary();
450 if (devtools_observer_)
451 devtools_observer_->OnViewEnabledChanged(this, enabled);
439 OnEnabledChanged(); 452 OnEnabledChanged();
440 } 453 }
441 } 454 }
442 455
443 void View::OnEnabledChanged() { 456 void View::OnEnabledChanged() {
444 SchedulePaint(); 457 SchedulePaint();
445 } 458 }
446 459
447 // Transformations ------------------------------------------------------------- 460 // Transformations -------------------------------------------------------------
448 461
(...skipping 1383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1832 if (delete_removed_view && !view->owned_by_client_) 1845 if (delete_removed_view && !view->owned_by_client_)
1833 view_to_be_deleted.reset(view); 1846 view_to_be_deleted.reset(view);
1834 1847
1835 children_.erase(i); 1848 children_.erase(i);
1836 1849
1837 if (update_tool_tip) 1850 if (update_tool_tip)
1838 UpdateTooltip(); 1851 UpdateTooltip();
1839 1852
1840 if (layout_manager_) 1853 if (layout_manager_)
1841 layout_manager_->ViewRemoved(this, view); 1854 layout_manager_->ViewRemoved(this, view);
1855
1856 // We don't care about the new_parent here because if there is one,
1857 // devtools will be notified in the AddChildViewAt method.
1858 if (devtools_observer_)
1859 devtools_observer_->OnViewHierarchyChanged(view, this, nullptr);
1842 } 1860 }
1843 1861
1844 void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) { 1862 void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) {
1845 for (int i = 0, count = child_count(); i < count; ++i) 1863 for (int i = 0, count = child_count(); i < count; ++i)
1846 child_at(i)->PropagateRemoveNotifications(old_parent, new_parent); 1864 child_at(i)->PropagateRemoveNotifications(old_parent, new_parent);
1847 1865
1848 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent); 1866 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent);
1849 for (View* v = this; v; v = v->parent_) 1867 for (View* v = this; v; v = v->parent_)
1850 v->ViewHierarchyChangedImpl(true, details); 1868 v->ViewHierarchyChangedImpl(true, details);
1851 } 1869 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 1908
1891 // Size and disposition -------------------------------------------------------- 1909 // Size and disposition --------------------------------------------------------
1892 1910
1893 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { 1911 void View::PropagateVisibilityNotifications(View* start, bool is_visible) {
1894 for (int i = 0, count = child_count(); i < count; ++i) 1912 for (int i = 0, count = child_count(); i < count; ++i)
1895 child_at(i)->PropagateVisibilityNotifications(start, is_visible); 1913 child_at(i)->PropagateVisibilityNotifications(start, is_visible);
1896 VisibilityChangedImpl(start, is_visible); 1914 VisibilityChangedImpl(start, is_visible);
1897 } 1915 }
1898 1916
1899 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { 1917 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) {
1918 if (devtools_observer_)
1919 devtools_observer_->OnViewVisibilityChanged(starting_from, is_visible);
1900 VisibilityChanged(starting_from, is_visible); 1920 VisibilityChanged(starting_from, is_visible);
1901 } 1921 }
1902 1922
1903 void View::BoundsChanged(const gfx::Rect& previous_bounds) { 1923 void View::BoundsChanged(const gfx::Rect& previous_bounds) {
1904 if (visible_) { 1924 if (visible_) {
1905 // Paint the new bounds. 1925 // Paint the new bounds.
1906 SchedulePaintBoundsChanged( 1926 SchedulePaintBoundsChanged(
1907 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : 1927 bounds_.size() == previous_bounds.size() ? SCHEDULE_PAINT_SIZE_SAME :
1908 SCHEDULE_PAINT_SIZE_CHANGED); 1928 SCHEDULE_PAINT_SIZE_CHANGED);
1909 } 1929 }
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
2415 // Message the RootView to do the drag and drop. That way if we're removed 2435 // Message the RootView to do the drag and drop. That way if we're removed
2416 // the RootView can detect it and avoid calling us back. 2436 // the RootView can detect it and avoid calling us back.
2417 gfx::Point widget_location(event.location()); 2437 gfx::Point widget_location(event.location());
2418 ConvertPointToWidget(this, &widget_location); 2438 ConvertPointToWidget(this, &widget_location);
2419 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2439 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2420 // WARNING: we may have been deleted. 2440 // WARNING: we may have been deleted.
2421 return true; 2441 return true;
2422 } 2442 }
2423 2443
2424 } // namespace views 2444 } // namespace views
OLDNEW
« ui/views/devtools_observer.h ('K') | « ui/views/view.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698