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

Side by Side Diff: ui/touch_selection/touch_handle_drawable_aura.cc

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 5 years, 2 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/touch_selection/touch_handle_drawable_aura.h" 5 #include "ui/touch_selection/touch_handle_drawable_aura.h"
6 6
7 #include "ui/aura/window.h" 7 #include "ui/aura/window.h"
8 #include "ui/aura/window_targeter.h" 8 #include "ui/aura/window_targeter.h"
9 #include "ui/aura_extra/image_window_delegate.h" 9 #include "ui/aura_extra/image_window_delegate.h"
10 #include "ui/base/cursor/cursor.h" 10 #include "ui/base/cursor/cursor.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 window_->set_owned_by_parent(false); 70 window_->set_owned_by_parent(false);
71 window_->set_ignore_events(true); 71 window_->set_ignore_events(true);
72 parent->AddChild(window_.get()); 72 parent->AddChild(window_.get());
73 } 73 }
74 74
75 TouchHandleDrawableAura::~TouchHandleDrawableAura() { 75 TouchHandleDrawableAura::~TouchHandleDrawableAura() {
76 } 76 }
77 77
78 void TouchHandleDrawableAura::UpdateBounds() { 78 void TouchHandleDrawableAura::UpdateBounds() {
79 gfx::RectF new_bounds = relative_bounds_; 79 gfx::RectF new_bounds = relative_bounds_;
80 new_bounds.Offset(focal_position_.x(), focal_position_.y()); 80 new_bounds.Offset(origin_position_.x(), origin_position_.y());
81 window_->SetBounds(gfx::ToEnclosingRect(new_bounds)); 81 window_->SetBounds(gfx::ToEnclosingRect(new_bounds));
82 } 82 }
83 83
84 bool TouchHandleDrawableAura::IsVisible() const { 84 bool TouchHandleDrawableAura::IsVisible() const {
85 return enabled_ && !IsNearlyZero(alpha_); 85 return enabled_ && !IsNearlyZero(alpha_);
86 } 86 }
87 87
88 void TouchHandleDrawableAura::SetEnabled(bool enabled) { 88 void TouchHandleDrawableAura::SetEnabled(bool enabled) {
89 if (enabled == enabled_) 89 if (enabled == enabled_)
90 return; 90 return;
91 91
92 enabled_ = enabled; 92 enabled_ = enabled;
93 if (IsVisible()) 93 if (IsVisible())
94 window_->Show(); 94 window_->Show();
95 else 95 else
96 window_->Hide(); 96 window_->Hide();
97 } 97 }
98 98
99 void TouchHandleDrawableAura::SetOrientation( 99 void TouchHandleDrawableAura::SetOrientation(TouchHandleOrientation orientation,
100 TouchHandleOrientation orientation) { 100 bool mirror_vertical,
101 bool mirror_horizontal) {
102 // TODO(AviD): Implement adaptive handle orientation logic for Aura
103 DCHECK(!mirror_vertical);
104 DCHECK(!mirror_horizontal);
105
101 if (orientation_ == orientation) 106 if (orientation_ == orientation)
102 return; 107 return;
103 orientation_ = orientation; 108 orientation_ = orientation;
104 gfx::Image* image = GetHandleImage(orientation); 109 gfx::Image* image = GetHandleImage(orientation);
105 window_delegate_->SetImage(*image); 110 window_delegate_->SetImage(*image);
106 111
107 // Calculate the relative bounds. 112 // Calculate the relative bounds.
108 gfx::Size image_size = image->Size(); 113 gfx::Size image_size = image->Size();
109 int window_width = image_size.width() + 2 * kSelectionHandlePadding; 114 int window_width = image_size.width() + 2 * kSelectionHandlePadding;
110 int window_height = image_size.height() + 2 * kSelectionHandlePadding; 115 int window_height = image_size.height() + 2 * kSelectionHandlePadding;
111 // Due to the shape of the handle images, the window is aligned differently to 116 relative_bounds_ =
112 // the selection bound depending on the orientation. 117 gfx::RectF(-kSelectionHandlePadding,
113 int window_left = 0; 118 kSelectionHandleVerticalVisualOffset - kSelectionHandlePadding,
114 switch (orientation) { 119 window_width, window_height);
115 case TouchHandleOrientation::LEFT:
116 window_left = -image_size.width() - kSelectionHandlePadding;
117 break;
118 case TouchHandleOrientation::RIGHT:
119 window_left = -kSelectionHandlePadding;
120 break;
121 case TouchHandleOrientation::CENTER:
122 window_left = -window_width / 2;
123 break;
124 case TouchHandleOrientation::UNDEFINED:
125 NOTREACHED() << "Undefined handle orientation.";
126 break;
127 };
128 relative_bounds_ = gfx::RectF(
129 window_left,
130 kSelectionHandleVerticalVisualOffset - kSelectionHandlePadding,
131 window_width,
132 window_height);
133 UpdateBounds(); 120 UpdateBounds();
134 } 121 }
135 122
123 void TouchHandleDrawableAura::SetOrigin(const gfx::PointF& position) {
124 origin_position_ = position;
125 UpdateBounds();
126 }
127
136 void TouchHandleDrawableAura::SetAlpha(float alpha) { 128 void TouchHandleDrawableAura::SetAlpha(float alpha) {
137 if (alpha == alpha_) 129 if (alpha == alpha_)
138 return; 130 return;
139 131
140 alpha_ = alpha; 132 alpha_ = alpha;
141 window_->layer()->SetOpacity(alpha_); 133 window_->layer()->SetOpacity(alpha_);
142 if (IsVisible()) 134 if (IsVisible())
143 window_->Show(); 135 window_->Show();
144 else 136 else
145 window_->Hide(); 137 window_->Hide();
146 } 138 }
147 139
148 void TouchHandleDrawableAura::SetFocus(const gfx::PointF& position) {
149 focal_position_ = position;
150 UpdateBounds();
151 }
152
153 gfx::RectF TouchHandleDrawableAura::GetVisibleBounds() const { 140 gfx::RectF TouchHandleDrawableAura::GetVisibleBounds() const {
154 gfx::RectF bounds(window_->bounds()); 141 gfx::RectF bounds(window_->bounds());
155 bounds.Inset(kSelectionHandlePadding, 142 bounds.Inset(kSelectionHandlePadding,
156 kSelectionHandlePadding + kSelectionHandleVerticalVisualOffset, 143 kSelectionHandlePadding + kSelectionHandleVerticalVisualOffset,
157 kSelectionHandlePadding, 144 kSelectionHandlePadding,
158 kSelectionHandlePadding); 145 kSelectionHandlePadding);
159 return bounds; 146 return bounds;
160 } 147 }
161 148
149 float TouchHandleDrawableAura::GetDrawableHorizontalPaddingRatio() const {
150 // Aura does not have any transparent padding for its handle drawable.
151 return 0.0f;
152 }
153
162 } // namespace ui 154 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_handle_drawable_aura.h ('k') | ui/touch_selection/touch_handle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698