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

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

Issue 375693006: Snap layers in views to physical pixel (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use cc::MathUtil::Round instead Created 6 years, 5 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 | Annotate | Revision Log
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>
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
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
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() {
578 if (!layer())
579 return;
580
581 if (snap_layer_to_pixel_boundary_ && layer()->parent() &&
582 layer()->GetCompositor()) {
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 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
1513 } 1528 }
1514 } 1529 }
1515 1530
1516 void View::OnPaintLayer(gfx::Canvas* canvas) { 1531 void View::OnPaintLayer(gfx::Canvas* canvas) {
1517 if (!layer() || !layer()->fills_bounds_opaquely()) 1532 if (!layer() || !layer()->fills_bounds_opaquely())
1518 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 1533 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
1519 PaintCommon(canvas, CullSet()); 1534 PaintCommon(canvas, CullSet());
1520 } 1535 }
1521 1536
1522 void View::OnDeviceScaleFactorChanged(float device_scale_factor) { 1537 void View::OnDeviceScaleFactorChanged(float device_scale_factor) {
1538 snap_layer_to_pixel_boundary_ =
1539 (device_scale_factor - std::floor(device_scale_factor)) != 0.0f;
1540 SnapLayerToPixelBoundary();
1523 // Repainting with new scale factor will paint the content at the right scale. 1541 // Repainting with new scale factor will paint the content at the right scale.
1524 } 1542 }
1525 1543
1526 base::Closure View::PrepareForLayerBoundsChange() { 1544 base::Closure View::PrepareForLayerBoundsChange() {
1527 return base::Closure(); 1545 return base::Closure();
1528 } 1546 }
1529 1547
1530 void View::ReorderLayers() { 1548 void View::ReorderLayers() {
1531 View* v = this; 1549 View* v = this;
1532 while (v && !v->layer()) 1550 while (v && !v->layer())
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 Views::iterator i(std::find( 2051 Views::iterator i(std::find(
2034 descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); 2052 descendants_to_notify_->begin(), descendants_to_notify_->end(), view));
2035 DCHECK(i != descendants_to_notify_->end()); 2053 DCHECK(i != descendants_to_notify_->end());
2036 descendants_to_notify_->erase(i); 2054 descendants_to_notify_->erase(i);
2037 if (descendants_to_notify_->empty()) 2055 if (descendants_to_notify_->empty())
2038 descendants_to_notify_.reset(); 2056 descendants_to_notify_.reset();
2039 } 2057 }
2040 2058
2041 void View::SetLayerBounds(const gfx::Rect& bounds) { 2059 void View::SetLayerBounds(const gfx::Rect& bounds) {
2042 layer()->SetBounds(bounds); 2060 layer()->SetBounds(bounds);
2061 SnapLayerToPixelBoundary();
2043 } 2062 }
2044 2063
2045 void View::SetRootBoundsDirty(bool origin_changed) { 2064 void View::SetRootBoundsDirty(bool origin_changed) {
2046 root_bounds_dirty_ = true; 2065 root_bounds_dirty_ = true;
2047 2066
2048 if (origin_changed) { 2067 if (origin_changed) {
2049 // Inform our children that their root bounds are dirty, as their relative 2068 // Inform our children that their root bounds are dirty, as their relative
2050 // coordinates in paint root space have changed since ours have changed. 2069 // coordinates in paint root space have changed since ours have changed.
2051 for (Views::const_iterator i(children_.begin()); i != children_.end(); 2070 for (Views::const_iterator i(children_.begin()); i != children_.end();
2052 ++i) { 2071 ++i) {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 // Message the RootView to do the drag and drop. That way if we're removed 2494 // Message the RootView to do the drag and drop. That way if we're removed
2476 // the RootView can detect it and avoid calling us back. 2495 // the RootView can detect it and avoid calling us back.
2477 gfx::Point widget_location(event.location()); 2496 gfx::Point widget_location(event.location());
2478 ConvertPointToWidget(this, &widget_location); 2497 ConvertPointToWidget(this, &widget_location);
2479 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2498 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2480 // WARNING: we may have been deleted. 2499 // WARNING: we may have been deleted.
2481 return true; 2500 return true;
2482 } 2501 }
2483 2502
2484 } // namespace views 2503 } // namespace views
OLDNEW
« ui/compositor/dip_util.cc ('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