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

Side by Side Diff: views/touchui/touch_selection_controller_impl.cc

Issue 7696013: Minor fix to touch selection logic. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 4 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
« no previous file with comments | « views/touchui/touch_selection_controller_impl.h ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "views/touchui/touch_selection_controller_impl.h" 5 #include "views/touchui/touch_selection_controller_impl.h"
6 6
7 #include "ui/gfx/canvas.h" 7 #include "ui/gfx/canvas.h"
8 #include "ui/gfx/canvas_skia.h" 8 #include "ui/gfx/canvas_skia.h"
9 #include "ui/gfx/path.h" 9 #include "ui/gfx/path.h"
10 #include "ui/gfx/rect.h" 10 #include "ui/gfx/rect.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 void TouchSelectionControllerImpl::SelectionChanged(const gfx::Point& p1, 155 void TouchSelectionControllerImpl::SelectionChanged(const gfx::Point& p1,
156 const gfx::Point& p2) { 156 const gfx::Point& p2) {
157 gfx::Point screen_pos_1(p1); 157 gfx::Point screen_pos_1(p1);
158 View::ConvertPointToScreen(client_view_, &screen_pos_1); 158 View::ConvertPointToScreen(client_view_, &screen_pos_1);
159 gfx::Point screen_pos_2(p2); 159 gfx::Point screen_pos_2(p2);
160 View::ConvertPointToScreen(client_view_, &screen_pos_2); 160 View::ConvertPointToScreen(client_view_, &screen_pos_2);
161 161
162 if (dragging_handle_) { 162 if (dragging_handle_) {
163 // We need to reposition only the selection handle that is being dragged. 163 // We need to reposition only the selection handle that is being dragged.
164 // The other handle stays the same. 164 // The other handle stays the same. Also, the selection handle being dragged
165 SelectionHandleView* fixed_handle = selection_handle_1_.get(); 165 // will always be at the end of selection, while the other handle will be at
166 if (fixed_handle == dragging_handle_) 166 // the start.
167 fixed_handle = selection_handle_2_.get(); 167 dragging_handle_->SetScreenPosition(screen_pos_2);
168
169 gfx::Point fixed_handle_pos = fixed_handle->GetScreenPosition();
170 fixed_handle_pos.Offset(kSelectionHandleRadius, 0);
171
172 if (fixed_handle_pos == screen_pos_1)
173 dragging_handle_->SetScreenPosition(screen_pos_2);
174 else
175 dragging_handle_->SetScreenPosition(screen_pos_1);
176 } else { 168 } else {
177 // Check if there is any selection at all. 169 // Check if there is any selection at all.
178 if (screen_pos_1 == screen_pos_2) { 170 if (screen_pos_1 == screen_pos_2) {
179 selection_handle_1_->SetVisible(false); 171 selection_handle_1_->SetVisible(false);
180 selection_handle_2_->SetVisible(false); 172 selection_handle_2_->SetVisible(false);
181 return; 173 return;
182 } 174 }
183 175
184 if (client_view_->bounds().Contains(p1)) { 176 if (isPointInClientView(p1)) {
185 selection_handle_1_->SetScreenPosition(screen_pos_1); 177 selection_handle_1_->SetScreenPosition(screen_pos_1);
186 selection_handle_1_->SetVisible(true); 178 selection_handle_1_->SetVisible(true);
187 } else { 179 } else {
188 selection_handle_1_->SetVisible(false); 180 selection_handle_1_->SetVisible(false);
189 } 181 }
190 182
191 if (client_view_->bounds().Contains(p2)) { 183 if (isPointInClientView(p2)) {
192 selection_handle_2_->SetScreenPosition(screen_pos_2); 184 selection_handle_2_->SetScreenPosition(screen_pos_2);
193 selection_handle_2_->SetVisible(true); 185 selection_handle_2_->SetVisible(true);
194 } else { 186 } else {
195 selection_handle_2_->SetVisible(false); 187 selection_handle_2_->SetVisible(false);
196 } 188 }
197 } 189 }
198 } 190 }
199 191
200 void TouchSelectionControllerImpl::ClientViewLostFocus() { 192 void TouchSelectionControllerImpl::ClientViewLostFocus() {
201 selection_handle_1_->SetVisible(false); 193 selection_handle_1_->SetVisible(false);
(...skipping 24 matching lines...) Expand all
226 } 218 }
227 219
228 void TouchSelectionControllerImpl::ConvertPointToClientView( 220 void TouchSelectionControllerImpl::ConvertPointToClientView(
229 SelectionHandleView* source, gfx::Point* point) { 221 SelectionHandleView* source, gfx::Point* point) {
230 View::ConvertPointToScreen(source, point); 222 View::ConvertPointToScreen(source, point);
231 gfx::Rect r = client_view_->GetWidget()->GetClientAreaScreenBounds(); 223 gfx::Rect r = client_view_->GetWidget()->GetClientAreaScreenBounds();
232 point->SetPoint(point->x() - r.x(), point->y() - r.y()); 224 point->SetPoint(point->x() - r.x(), point->y() - r.y());
233 View::ConvertPointFromWidget(client_view_, point); 225 View::ConvertPointFromWidget(client_view_, point);
234 } 226 }
235 227
228 bool TouchSelectionControllerImpl::isPointInClientView(const gfx::Point& p) {
sky 2011/08/22 14:21:37 is -> Is
varunjain 2011/08/22 16:58:50 Done.
229 gfx::Rect r = client_view_->bounds();
230 return p.x() >= r.x() && p.x() <= r.x() + r.width() &&
sky 2011/08/22 14:21:37 return r.Contains(p)
varunjain 2011/08/22 16:58:50 Rect::Contains checks for strict inclusion and ret
231 p.y() >= r.y() && p.y() <= r.y() + r.height();
232 }
233
236 gfx::Point TouchSelectionControllerImpl::GetSelectionHandle1Position() { 234 gfx::Point TouchSelectionControllerImpl::GetSelectionHandle1Position() {
237 return selection_handle_1_->GetScreenPosition(); 235 return selection_handle_1_->GetScreenPosition();
238 } 236 }
239 237
240 gfx::Point TouchSelectionControllerImpl::GetSelectionHandle2Position() { 238 gfx::Point TouchSelectionControllerImpl::GetSelectionHandle2Position() {
241 return selection_handle_2_->GetScreenPosition(); 239 return selection_handle_2_->GetScreenPosition();
242 } 240 }
243 241
244 bool TouchSelectionControllerImpl::IsSelectionHandle1Visible() { 242 bool TouchSelectionControllerImpl::IsSelectionHandle1Visible() {
245 return selection_handle_1_->IsVisible(); 243 return selection_handle_1_->IsVisible();
246 } 244 }
247 245
248 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { 246 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() {
249 return selection_handle_2_->IsVisible(); 247 return selection_handle_2_->IsVisible();
250 } 248 }
251 249
252 TouchSelectionController* TouchSelectionController::create( 250 TouchSelectionController* TouchSelectionController::create(
253 TouchSelectionClientView* client_view) { 251 TouchSelectionClientView* client_view) {
254 return new TouchSelectionControllerImpl(client_view); 252 return new TouchSelectionControllerImpl(client_view);
255 } 253 }
256 254
257 } // namespace views 255 } // namespace views
OLDNEW
« no previous file with comments | « views/touchui/touch_selection_controller_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698