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

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

Issue 2500623002: Add ViewObserver to View for view updates (Closed)
Patch Set: Add DevToolsobserver to View for view updates 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_(NULL) {
sadrul 2016/11/15 17:21:49 nullptr
Sarmad Hashmi 2016/11/15 17:54:56 Done.
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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 children_.erase(i); 238 children_.erase(i);
237 239
238 // Unlink the view first 240 // Unlink the view first
239 View* next_focusable = view->next_focusable_view_; 241 View* next_focusable = view->next_focusable_view_;
240 View* prev_focusable = view->previous_focusable_view_; 242 View* prev_focusable = view->previous_focusable_view_;
241 if (prev_focusable) 243 if (prev_focusable)
242 prev_focusable->next_focusable_view_ = next_focusable; 244 prev_focusable->next_focusable_view_ = next_focusable;
243 if (next_focusable) 245 if (next_focusable)
244 next_focusable->previous_focusable_view_ = prev_focusable; 246 next_focusable->previous_focusable_view_ = prev_focusable;
245 247
248 if (devtools_observer_)
249 devtools_observer_->OnChildViewReordered(view, index);
250
246 // Add it in the specified index now. 251 // Add it in the specified index now.
247 InitFocusSiblings(view, index); 252 InitFocusSiblings(view, index);
248 children_.insert(children_.begin() + index, view); 253 children_.insert(children_.begin() + index, view);
249 254
250 ReorderLayers(); 255 ReorderLayers();
251 } 256 }
252 257
253 void View::RemoveChildView(View* view) { 258 void View::RemoveChildView(View* view) {
254 DoRemoveChildView(view, true, true, false, NULL); 259 DoRemoveChildView(view, true, true, false, NULL);
255 } 260 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 return; 293 return;
289 } 294 }
290 295
291 if (visible_) { 296 if (visible_) {
292 // Paint where the view is currently. 297 // Paint where the view is currently.
293 SchedulePaintBoundsChanged( 298 SchedulePaintBoundsChanged(
294 bounds_.size() == bounds.size() ? SCHEDULE_PAINT_SIZE_SAME : 299 bounds_.size() == bounds.size() ? SCHEDULE_PAINT_SIZE_SAME :
295 SCHEDULE_PAINT_SIZE_CHANGED); 300 SCHEDULE_PAINT_SIZE_CHANGED);
296 } 301 }
297 302
303 if (devtools_observer_)
304 devtools_observer_->OnViewBoundsChanged(this, bounds);
305
298 gfx::Rect prev = bounds_; 306 gfx::Rect prev = bounds_;
299 bounds_ = bounds; 307 bounds_ = bounds;
300 BoundsChanged(prev); 308 BoundsChanged(prev);
301 } 309 }
302 310
303 void View::SetSize(const gfx::Size& size) { 311 void View::SetSize(const gfx::Size& size) {
304 SetBounds(x(), y(), size.width(), size.height()); 312 SetBounds(x(), y(), size.width(), size.height());
305 } 313 }
306 314
307 void View::SetPosition(const gfx::Point& position) { 315 void View::SetPosition(const gfx::Point& position) {
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 } 437 }
430 438
431 bool View::IsDrawn() const { 439 bool View::IsDrawn() const {
432 return visible_ && parent_ ? parent_->IsDrawn() : false; 440 return visible_ && parent_ ? parent_->IsDrawn() : false;
433 } 441 }
434 442
435 void View::SetEnabled(bool enabled) { 443 void View::SetEnabled(bool enabled) {
436 if (enabled != enabled_) { 444 if (enabled != enabled_) {
437 enabled_ = enabled; 445 enabled_ = enabled;
438 AdvanceFocusIfNecessary(); 446 AdvanceFocusIfNecessary();
447 if (devtools_observer_)
448 devtools_observer_->OnViewEnabledChanged(this, enabled);
439 OnEnabledChanged(); 449 OnEnabledChanged();
440 } 450 }
441 } 451 }
442 452
443 void View::OnEnabledChanged() { 453 void View::OnEnabledChanged() {
444 SchedulePaint(); 454 SchedulePaint();
445 } 455 }
446 456
447 // Transformations ------------------------------------------------------------- 457 // Transformations -------------------------------------------------------------
448 458
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 int View::GetPageScrollIncrement(ScrollView* scroll_view, 1367 int View::GetPageScrollIncrement(ScrollView* scroll_view,
1358 bool is_horizontal, bool is_positive) { 1368 bool is_horizontal, bool is_positive) {
1359 return 0; 1369 return 0;
1360 } 1370 }
1361 1371
1362 int View::GetLineScrollIncrement(ScrollView* scroll_view, 1372 int View::GetLineScrollIncrement(ScrollView* scroll_view,
1363 bool is_horizontal, bool is_positive) { 1373 bool is_horizontal, bool is_positive) {
1364 return 0; 1374 return 0;
1365 } 1375 }
1366 1376
1377 // DevTools Observer ---------------------------------------------------------
1378
1379 void View::SetDevToolsObserver(DevToolsObserver* devtools_observer) {
1380 devtools_observer_ = devtools_observer;
1381 }
1382
1367 //////////////////////////////////////////////////////////////////////////////// 1383 ////////////////////////////////////////////////////////////////////////////////
1368 // View, protected: 1384 // View, protected:
1369 1385
1370 // Size and disposition -------------------------------------------------------- 1386 // Size and disposition --------------------------------------------------------
1371 1387
1372 void View::OnBoundsChanged(const gfx::Rect& previous_bounds) { 1388 void View::OnBoundsChanged(const gfx::Rect& previous_bounds) {
1373 } 1389 }
1374 1390
1375 void View::PreferredSizeChanged() { 1391 void View::PreferredSizeChanged() {
1376 InvalidateLayout(); 1392 InvalidateLayout();
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1871 // If you get this registration, you are part of a subtree that has been 1887 // If you get this registration, you are part of a subtree that has been
1872 // added to the view hierarchy. 1888 // added to the view hierarchy.
1873 if (GetFocusManager()) 1889 if (GetFocusManager())
1874 RegisterPendingAccelerators(); 1890 RegisterPendingAccelerators();
1875 } else { 1891 } else {
1876 if (details.child == this) 1892 if (details.child == this)
1877 UnregisterAccelerators(true); 1893 UnregisterAccelerators(true);
1878 } 1894 }
1879 } 1895 }
1880 1896
1897 if (devtools_observer_)
1898 devtools_observer_->OnViewHierarchyChanged(this, details);
sadrul 2016/11/15 17:21:49 Is this the right place for this? Should this be i
Sarmad Hashmi 2016/11/15 17:54:56 ViewHierarchyChangedImpl is called from the Propog
1881 ViewHierarchyChanged(details); 1899 ViewHierarchyChanged(details);
1882 details.parent->needs_layout_ = true; 1900 details.parent->needs_layout_ = true;
1883 } 1901 }
1884 1902
1885 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { 1903 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) {
1886 for (int i = 0, count = child_count(); i < count; ++i) 1904 for (int i = 0, count = child_count(); i < count; ++i)
1887 child_at(i)->PropagateNativeThemeChanged(theme); 1905 child_at(i)->PropagateNativeThemeChanged(theme);
1888 OnNativeThemeChanged(theme); 1906 OnNativeThemeChanged(theme);
1889 } 1907 }
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

Powered by Google App Engine
This is Rietveld 408576698