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 #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> |
11 | 11 |
12 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
19 #include "ui/accessibility/ax_enums.h" | 19 #include "ui/accessibility/ax_enums.h" |
20 #include "ui/base/cursor/cursor.h" | 20 #include "ui/base/cursor/cursor.h" |
21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
22 #include "ui/compositor/compositor.h" | 22 #include "ui/compositor/compositor.h" |
23 #include "ui/compositor/dip_util.h" | |
23 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
24 #include "ui/compositor/layer_animator.h" | 25 #include "ui/compositor/layer_animator.h" |
25 #include "ui/events/event_target_iterator.h" | 26 #include "ui/events/event_target_iterator.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/interpolated_transform.h" | 28 #include "ui/gfx/interpolated_transform.h" |
28 #include "ui/gfx/path.h" | 29 #include "ui/gfx/path.h" |
29 #include "ui/gfx/point3_f.h" | 30 #include "ui/gfx/point3_f.h" |
30 #include "ui/gfx/point_conversions.h" | 31 #include "ui/gfx/point_conversions.h" |
31 #include "ui/gfx/rect_conversions.h" | 32 #include "ui/gfx/rect_conversions.h" |
32 #include "ui/gfx/scoped_canvas.h" | 33 #include "ui/gfx/scoped_canvas.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 id_(0), | 106 id_(0), |
106 group_(-1), | 107 group_(-1), |
107 parent_(NULL), | 108 parent_(NULL), |
108 visible_(true), | 109 visible_(true), |
109 enabled_(true), | 110 enabled_(true), |
110 notify_enter_exit_on_child_(false), | 111 notify_enter_exit_on_child_(false), |
111 registered_for_visible_bounds_notification_(false), | 112 registered_for_visible_bounds_notification_(false), |
112 root_bounds_dirty_(true), | 113 root_bounds_dirty_(true), |
113 clip_insets_(0, 0, 0, 0), | 114 clip_insets_(0, 0, 0, 0), |
114 needs_layout_(true), | 115 needs_layout_(true), |
116 snap_layer_to_pixel_boundary_(false), | |
115 flip_canvas_on_paint_for_rtl_ui_(false), | 117 flip_canvas_on_paint_for_rtl_ui_(false), |
116 paint_to_layer_(false), | 118 paint_to_layer_(false), |
117 accelerator_focus_manager_(NULL), | 119 accelerator_focus_manager_(NULL), |
118 registered_accelerator_count_(0), | 120 registered_accelerator_count_(0), |
119 next_focusable_view_(NULL), | 121 next_focusable_view_(NULL), |
120 previous_focusable_view_(NULL), | 122 previous_focusable_view_(NULL), |
121 focusable_(false), | 123 focusable_(false), |
122 accessibility_focusable_(false), | 124 accessibility_focusable_(false), |
123 context_menu_controller_(NULL), | 125 context_menu_controller_(NULL), |
124 drag_controller_(NULL), | 126 drag_controller_(NULL), |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 | 567 |
566 void View::SetLayoutManager(LayoutManager* layout_manager) { | 568 void View::SetLayoutManager(LayoutManager* layout_manager) { |
567 if (layout_manager_.get()) | 569 if (layout_manager_.get()) |
568 layout_manager_->Uninstalled(this); | 570 layout_manager_->Uninstalled(this); |
569 | 571 |
570 layout_manager_.reset(layout_manager); | 572 layout_manager_.reset(layout_manager); |
571 if (layout_manager_.get()) | 573 if (layout_manager_.get()) |
572 layout_manager_->Installed(this); | 574 layout_manager_->Installed(this); |
573 } | 575 } |
574 | 576 |
577 void View::SnapLayerToPixelBoundary() { | |
Ben Goodger (Google)
2014/07/08 16:07:34
should this be implemented in Layer?
oshima
2014/07/08 17:39:18
Layer currently does not know which layers are ali
| |
578 if (!layer()) | |
579 return; | |
580 | |
581 if (snap_layer_to_pixel_boundary_ && | |
582 layer()->parent() && layer()->GetCompositor()) { | |
danakj
2014/07/15 21:11:02
why the check for GetCompositor?
oshima
2014/07/15 22:28:42
Because view can exist without parent nor widget.
| |
583 ui::SnapLayerToPhysicalPixelBoundary(layer()->parent(), layer()); | |
584 } else { | |
585 // Reset the offset. | |
586 layer()->SetSubpixelPositionOffset(gfx::Vector2dF()); | |
587 } | |
588 } | |
589 | |
575 // Attributes ------------------------------------------------------------------ | 590 // Attributes ------------------------------------------------------------------ |
576 | 591 |
577 const char* View::GetClassName() const { | 592 const char* View::GetClassName() const { |
578 return kViewClassName; | 593 return kViewClassName; |
579 } | 594 } |
580 | 595 |
581 const View* View::GetAncestorWithClassName(const std::string& name) const { | 596 const View* View::GetAncestorWithClassName(const std::string& name) const { |
582 for (const View* view = this; view; view = view->parent_) { | 597 for (const View* view = this; view; view = view->parent_) { |
583 if (!strcmp(view->GetClassName(), name.c_str())) | 598 if (!strcmp(view->GetClassName(), name.c_str())) |
584 return view; | 599 return view; |
(...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1535 } | 1550 } |
1536 } | 1551 } |
1537 | 1552 |
1538 void View::OnPaintLayer(gfx::Canvas* canvas) { | 1553 void View::OnPaintLayer(gfx::Canvas* canvas) { |
1539 if (!layer() || !layer()->fills_bounds_opaquely()) | 1554 if (!layer() || !layer()->fills_bounds_opaquely()) |
1540 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); | 1555 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); |
1541 PaintCommon(canvas, CullSet()); | 1556 PaintCommon(canvas, CullSet()); |
1542 } | 1557 } |
1543 | 1558 |
1544 void View::OnDeviceScaleFactorChanged(float device_scale_factor) { | 1559 void View::OnDeviceScaleFactorChanged(float device_scale_factor) { |
1560 snap_layer_to_pixel_boundary_ = | |
danakj
2014/07/15 21:11:02
Didn't you want this to be false for some layers l
oshima
2014/07/15 22:28:42
Yes, it'll be handled in a separate CL for ash. (s
| |
1561 (device_scale_factor - std::floor(device_scale_factor)) != 0.0f; | |
1562 SnapLayerToPixelBoundary(); | |
1545 // Repainting with new scale factor will paint the content at the right scale. | 1563 // Repainting with new scale factor will paint the content at the right scale. |
1546 } | 1564 } |
1547 | 1565 |
1548 base::Closure View::PrepareForLayerBoundsChange() { | 1566 base::Closure View::PrepareForLayerBoundsChange() { |
1549 return base::Closure(); | 1567 return base::Closure(); |
1550 } | 1568 } |
1551 | 1569 |
1552 void View::ReorderLayers() { | 1570 void View::ReorderLayers() { |
1553 View* v = this; | 1571 View* v = this; |
1554 while (v && !v->layer()) | 1572 while (v && !v->layer()) |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2064 Views::iterator i(std::find( | 2082 Views::iterator i(std::find( |
2065 descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); | 2083 descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); |
2066 DCHECK(i != descendants_to_notify_->end()); | 2084 DCHECK(i != descendants_to_notify_->end()); |
2067 descendants_to_notify_->erase(i); | 2085 descendants_to_notify_->erase(i); |
2068 if (descendants_to_notify_->empty()) | 2086 if (descendants_to_notify_->empty()) |
2069 descendants_to_notify_.reset(); | 2087 descendants_to_notify_.reset(); |
2070 } | 2088 } |
2071 | 2089 |
2072 void View::SetLayerBounds(const gfx::Rect& bounds) { | 2090 void View::SetLayerBounds(const gfx::Rect& bounds) { |
2073 layer()->SetBounds(bounds); | 2091 layer()->SetBounds(bounds); |
2092 SnapLayerToPixelBoundary(); | |
2074 } | 2093 } |
2075 | 2094 |
2076 void View::SetRootBoundsDirty(bool origin_changed) { | 2095 void View::SetRootBoundsDirty(bool origin_changed) { |
2077 root_bounds_dirty_ = true; | 2096 root_bounds_dirty_ = true; |
2078 | 2097 |
2079 if (origin_changed) { | 2098 if (origin_changed) { |
2080 // Inform our children that their root bounds are dirty, as their relative | 2099 // Inform our children that their root bounds are dirty, as their relative |
2081 // coordinates in paint root space have changed since ours have changed. | 2100 // coordinates in paint root space have changed since ours have changed. |
2082 for (Views::const_iterator i(children_.begin()); i != children_.end(); | 2101 for (Views::const_iterator i(children_.begin()); i != children_.end(); |
2083 ++i) { | 2102 ++i) { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2506 // Message the RootView to do the drag and drop. That way if we're removed | 2525 // Message the RootView to do the drag and drop. That way if we're removed |
2507 // the RootView can detect it and avoid calling us back. | 2526 // the RootView can detect it and avoid calling us back. |
2508 gfx::Point widget_location(event.location()); | 2527 gfx::Point widget_location(event.location()); |
2509 ConvertPointToWidget(this, &widget_location); | 2528 ConvertPointToWidget(this, &widget_location); |
2510 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2529 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2511 // WARNING: we may have been deleted. | 2530 // WARNING: we may have been deleted. |
2512 return true; | 2531 return true; |
2513 } | 2532 } |
2514 | 2533 |
2515 } // namespace views | 2534 } // namespace views |
OLD | NEW |