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

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

Issue 10221028: Move DIP translation from ui/aura to ui/compositor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: gyp fix Created 8 years, 7 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
« ui/gfx/compositor/layer.cc ('K') | « ui/ui.gyp ('k') | no next file » | 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 #include "ui/views/view.h" 5 #include "ui/views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 20 matching lines...) Expand all
31 #include "ui/views/widget/native_widget_private.h" 31 #include "ui/views/widget/native_widget_private.h"
32 #include "ui/views/widget/root_view.h" 32 #include "ui/views/widget/root_view.h"
33 #include "ui/views/widget/tooltip_manager.h" 33 #include "ui/views/widget/tooltip_manager.h"
34 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 #include "base/win/scoped_gdi_object.h" 37 #include "base/win/scoped_gdi_object.h"
38 #include "ui/views/accessibility/native_view_accessibility_win.h" 38 #include "ui/views/accessibility/native_view_accessibility_win.h"
39 #endif 39 #endif
40 40
41 #if defined(ENABLE_DIP)
42 #include "ui/gfx/monitor.h"
43 #include "ui/gfx/screen.h"
44 #endif
45
46 namespace { 41 namespace {
47 42
48 // Whether to use accelerated compositing when necessary (e.g. when a view has a 43 // Whether to use accelerated compositing when necessary (e.g. when a view has a
49 // transformation). 44 // transformation).
50 #if defined(USE_AURA) 45 #if defined(USE_AURA)
51 bool use_acceleration_when_possible = true; 46 bool use_acceleration_when_possible = true;
52 #else 47 #else
53 bool use_acceleration_when_possible = false; 48 bool use_acceleration_when_possible = false;
54 #endif 49 #endif
55 50
(...skipping 22 matching lines...) Expand all
78 }; 73 };
79 74
80 // Returns the top view in |view|'s hierarchy. 75 // Returns the top view in |view|'s hierarchy.
81 const views::View* GetHierarchyRoot(const views::View* view) { 76 const views::View* GetHierarchyRoot(const views::View* view) {
82 const views::View* root = view; 77 const views::View* root = view;
83 while (root && root->parent()) 78 while (root && root->parent())
84 root = root->parent(); 79 root = root->parent();
85 return root; 80 return root;
86 } 81 }
87 82
88 // Converts the rect in DIP coordinates in DIP to pixel coordinates.
89 gfx::Rect ConvertRectToPixel(const views::View* view,
90 const gfx::Rect& rect_in_dip) {
91 #if defined(ENABLE_DIP)
92 // If we don't know in which monitor the window is in, just assume
93 // it's in normal density for now.
94 // TODO(oshima): Re-compute layer_'s bounds when the window is
95 // attached to root window.
96 if (view->GetWidget() && view->GetWidget()->GetNativeView()) {
97 gfx::Monitor monitor = gfx::Screen::GetMonitorNearestWindow(
98 view->GetWidget()->GetNativeView());
99 return gfx::Rect(rect_in_dip.Scale(monitor.device_scale_factor()));
100 }
101 #endif
102 return rect_in_dip;
103 }
104
105 } // namespace 83 } // namespace
106 84
107 namespace views { 85 namespace views {
108 86
109 // static 87 // static
110 ViewsDelegate* ViewsDelegate::views_delegate = NULL; 88 ViewsDelegate* ViewsDelegate::views_delegate = NULL;
111 89
112 // static 90 // static
113 const char View::kViewClassName[] = "views/View"; 91 const char View::kViewClassName[] = "views/View";
114 92
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 x_rect = v->ConvertRectToParent(x_rect); 681 x_rect = v->ConvertRectToParent(x_rect);
704 return x_rect; 682 return x_rect;
705 } 683 }
706 684
707 // Painting -------------------------------------------------------------------- 685 // Painting --------------------------------------------------------------------
708 686
709 void View::SchedulePaint() { 687 void View::SchedulePaint() {
710 SchedulePaintInRect(GetLocalBounds()); 688 SchedulePaintInRect(GetLocalBounds());
711 } 689 }
712 690
713 void View::SchedulePaintInRect(const gfx::Rect& rect_in_dip) { 691 void View::SchedulePaintInRect(const gfx::Rect& rect) {
714 if (!visible_ || !painting_enabled_) 692 if (!visible_ || !painting_enabled_)
715 return; 693 return;
716 694
717 if (layer()) { 695 if (layer()) {
718 layer()->SchedulePaint(ConvertRectToPixel(this, rect_in_dip)); 696 layer()->SchedulePaint(rect);
719 } else if (parent_) { 697 } else if (parent_) {
720 // Translate the requested paint rect to the parent's coordinate system 698 // Translate the requested paint rect to the parent's coordinate system
721 // then pass this notification up to the parent. 699 // then pass this notification up to the parent.
722 parent_->SchedulePaintInRect(ConvertRectToParent(rect_in_dip)); 700 parent_->SchedulePaintInRect(ConvertRectToParent(rect));
723 } 701 }
724 } 702 }
725 703
726 void View::Paint(gfx::Canvas* canvas) { 704 void View::Paint(gfx::Canvas* canvas) {
727 TRACE_EVENT0("views", "View::Paint"); 705 TRACE_EVENT0("views", "View::Paint");
728 706
729 ScopedCanvas scoped_canvas(canvas); 707 ScopedCanvas scoped_canvas(canvas);
730 708
731 // Paint this View and its children, setting the clip rect to the bounds 709 // Paint this View and its children, setting the clip rect to the bounds
732 // of this View and translating the origin to the local bounds' top left 710 // of this View and translating the origin to the local bounds' top left
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1250 } else { 1228 } else {
1251 for (int i = 0, count = child_count(); i < count; ++i) { 1229 for (int i = 0, count = child_count(); i < count; ++i) {
1252 gfx::Point new_offset(offset.x() + child_at(i)->GetMirroredX(), 1230 gfx::Point new_offset(offset.x() + child_at(i)->GetMirroredX(),
1253 offset.y() + child_at(i)->y()); 1231 offset.y() + child_at(i)->y());
1254 child_at(i)->UpdateChildLayerBounds(new_offset); 1232 child_at(i)->UpdateChildLayerBounds(new_offset);
1255 } 1233 }
1256 } 1234 }
1257 } 1235 }
1258 1236
1259 void View::OnPaintLayer(gfx::Canvas* canvas) { 1237 void View::OnPaintLayer(gfx::Canvas* canvas) {
1260 #if defined(ENABLE_DIP)
1261 scoped_ptr<ScopedCanvas> scoped_canvas;
1262 if (layer() && GetWidget() && GetWidget()->GetNativeView()) {
1263 scoped_canvas.reset(new ScopedCanvas(canvas));
1264 float scale =
1265 gfx::Screen::GetMonitorNearestWindow(GetWidget()->GetNativeView()).
1266 device_scale_factor();
1267 canvas->sk_canvas()->scale(SkFloatToScalar(scale), SkFloatToScalar(scale));
1268 }
1269 #endif
1270
1271 if (!layer() || !layer()->fills_bounds_opaquely()) 1238 if (!layer() || !layer()->fills_bounds_opaquely())
1272 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode); 1239 canvas->DrawColor(SK_ColorBLACK, SkXfermode::kClear_Mode);
1273 PaintCommon(canvas); 1240 PaintCommon(canvas);
1274 } 1241 }
1275 1242
1276 void View::ReorderLayers() { 1243 void View::ReorderLayers() {
1277 View* v = this; 1244 View* v = this;
1278 while (v && !v->layer()) 1245 while (v && !v->layer())
1279 v = v->parent(); 1246 v = v->parent();
1280 1247
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1761 void View::RemoveDescendantToNotify(View* view) { 1728 void View::RemoveDescendantToNotify(View* view) {
1762 DCHECK(view && descendants_to_notify_.get()); 1729 DCHECK(view && descendants_to_notify_.get());
1763 Views::iterator i(std::find( 1730 Views::iterator i(std::find(
1764 descendants_to_notify_->begin(), descendants_to_notify_->end(), view)); 1731 descendants_to_notify_->begin(), descendants_to_notify_->end(), view));
1765 DCHECK(i != descendants_to_notify_->end()); 1732 DCHECK(i != descendants_to_notify_->end());
1766 descendants_to_notify_->erase(i); 1733 descendants_to_notify_->erase(i);
1767 if (descendants_to_notify_->empty()) 1734 if (descendants_to_notify_->empty())
1768 descendants_to_notify_.reset(); 1735 descendants_to_notify_.reset();
1769 } 1736 }
1770 1737
1771 void View::SetLayerBounds(const gfx::Rect& bounds_in_dip) { 1738 void View::SetLayerBounds(const gfx::Rect& bounds) {
1772 layer()->SetBounds(ConvertRectToPixel(this, bounds_in_dip)); 1739 layer()->SetBounds(bounds);
1773 } 1740 }
1774 1741
1775 // Transformations ------------------------------------------------------------- 1742 // Transformations -------------------------------------------------------------
1776 1743
1777 bool View::GetTransformRelativeTo(const View* ancestor, 1744 bool View::GetTransformRelativeTo(const View* ancestor,
1778 ui::Transform* transform) const { 1745 ui::Transform* transform) const {
1779 const View* p = this; 1746 const View* p = this;
1780 1747
1781 while (p && p != ancestor) { 1748 while (p && p != ancestor) {
1782 transform->ConcatTransform(p->GetTransform()); 1749 transform->ConcatTransform(p->GetTransform());
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after
2105 2072
2106 // Message the RootView to do the drag and drop. That way if we're removed 2073 // Message the RootView to do the drag and drop. That way if we're removed
2107 // the RootView can detect it and avoid calling us back. 2074 // the RootView can detect it and avoid calling us back.
2108 gfx::Point widget_location(event.location()); 2075 gfx::Point widget_location(event.location());
2109 ConvertPointToWidget(this, &widget_location); 2076 ConvertPointToWidget(this, &widget_location);
2110 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); 2077 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
2111 #endif // !defined(OS_MACOSX) 2078 #endif // !defined(OS_MACOSX)
2112 } 2079 }
2113 2080
2114 } // namespace views 2081 } // namespace views
OLDNEW
« ui/gfx/compositor/layer.cc ('K') | « ui/ui.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698