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

Side by Side Diff: views/view.cc

Issue 6334152: Clean up RTL methods.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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/view.h ('k') | views/view_text_utils.cc » ('j') | 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/view.h" 5 #include "views/view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #ifndef NDEBUG 8 #ifndef NDEBUG
9 #include <iostream> 9 #include <iostream>
10 #endif 10 #endif
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 gfx::Rect View::GetVisibleBounds() { 280 gfx::Rect View::GetVisibleBounds() {
281 if (!IsVisibleInRootView()) 281 if (!IsVisibleInRootView())
282 return gfx::Rect(); 282 return gfx::Rect();
283 gfx::Rect vis_bounds(0, 0, width(), height()); 283 gfx::Rect vis_bounds(0, 0, width(), height());
284 gfx::Rect ancestor_bounds; 284 gfx::Rect ancestor_bounds;
285 View* view = this; 285 View* view = this;
286 int root_x = 0; 286 int root_x = 0;
287 int root_y = 0; 287 int root_y = 0;
288 while (view != NULL && !vis_bounds.IsEmpty()) { 288 while (view != NULL && !vis_bounds.IsEmpty()) {
289 root_x += view->GetX(APPLY_MIRRORING_TRANSFORMATION); 289 root_x += view->GetMirroredX();
290 root_y += view->y(); 290 root_y += view->y();
291 vis_bounds.Offset(view->GetX(APPLY_MIRRORING_TRANSFORMATION), view->y()); 291 vis_bounds.Offset(view->GetMirroredX(), view->y());
292 View* ancestor = view->GetParent(); 292 View* ancestor = view->GetParent();
293 if (ancestor != NULL) { 293 if (ancestor != NULL) {
294 ancestor_bounds.SetRect(0, 0, ancestor->width(), 294 ancestor_bounds.SetRect(0, 0, ancestor->width(),
295 ancestor->height()); 295 ancestor->height());
296 vis_bounds = vis_bounds.Intersect(ancestor_bounds); 296 vis_bounds = vis_bounds.Intersect(ancestor_bounds);
297 } else if (!view->GetWidget()) { 297 } else if (!view->GetWidget()) {
298 // If the view has no Widget, we're not visible. Return an empty rect. 298 // If the view has no Widget, we're not visible. Return an empty rect.
299 return gfx::Rect(); 299 return gfx::Rect();
300 } 300 }
301 view = ancestor; 301 view = ancestor;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 SchedulePaint(); 371 SchedulePaint();
372 } 372 }
373 } 373 }
374 374
375 bool View::IsEnabled() const { 375 bool View::IsEnabled() const {
376 return enabled_; 376 return enabled_;
377 } 377 }
378 378
379 // RTL positioning ------------------------------------------------------------- 379 // RTL positioning -------------------------------------------------------------
380 380
381 gfx::Rect View::GetBounds(PositionMirroringSettings settings) const { 381 gfx::Rect View::GetMirroredBounds() const {
382 gfx::Rect bounds(bounds_); 382 gfx::Rect bounds(bounds_);
383 383 bounds.set_x(GetMirroredX());
384 // If the parent uses an RTL UI layout and if we are asked to transform the
385 // bounds to their mirrored position if necessary, then we should shift the
386 // rectangle appropriately.
387 if (settings == APPLY_MIRRORING_TRANSFORMATION)
388 bounds.set_x(MirroredX());
389
390 return bounds; 384 return bounds;
391 } 385 }
392 386
393 // y(), width() and height() are agnostic to the RTL UI layout of the 387 gfx::Point View::GetMirroredPosition() const {
394 // parent view. x(), on the other hand, is not. 388 return gfx::Point(GetMirroredX(), y());
395 int View::GetX(PositionMirroringSettings settings) const {
396 return settings == IGNORE_MIRRORING_TRANSFORMATION ? x() : MirroredX();
397 } 389 }
398 390
399 gfx::Point View::GetPosition() const { 391 int View::GetMirroredX() const {
400 return gfx::Point(GetX(APPLY_MIRRORING_TRANSFORMATION), y()); 392 View* parent = GetParent();
393 return parent ? parent->GetMirroredXForRect(bounds_) : x();
401 } 394 }
402 395
403 int View::MirroredX() const { 396 int View::GetMirroredXForRect(const gfx::Rect& bounds) const {
404 View* parent = GetParent(); 397 return base::i18n::IsRTL() ?
405 return parent ? parent->MirroredLeftPointForRect(bounds_) : x(); 398 (width() - bounds.x() - bounds.width()) : bounds.x();
406 } 399 }
407 400
408 int View::MirroredLeftPointForRect(const gfx::Rect& bounds) const { 401 int View::GetMirroredXInView(int x) const {
409 return base::i18n::IsRTL() ? 402 return base::i18n::IsRTL() ? width() - x : x;
410 (width() - bounds.x() - bounds.width()) : bounds.x(); 403 }
404
405 int View::GetMirroredXWithWidthInView(int x, int w) const {
406 return base::i18n::IsRTL() ? width() - x - w : x;
411 } 407 }
412 408
413 // Layout ---------------------------------------------------------------------- 409 // Layout ----------------------------------------------------------------------
414 410
415 void View::Layout() { 411 void View::Layout() {
416 needs_layout_ = false; 412 needs_layout_ = false;
417 413
418 // If we have a layout manager, let it handle the layout for us. 414 // If we have a layout manager, let it handle the layout for us.
419 if (layout_manager_.get()) { 415 if (layout_manager_.get()) {
420 layout_manager_->Layout(this); 416 layout_manager_->Layout(this);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 ConvertPointToView(src, dst, point, true); 524 ConvertPointToView(src, dst, point, true);
529 } 525 }
530 526
531 // static 527 // static
532 void View::ConvertPointToWidget(const View* src, gfx::Point* p) { 528 void View::ConvertPointToWidget(const View* src, gfx::Point* p) {
533 DCHECK(src); 529 DCHECK(src);
534 DCHECK(p); 530 DCHECK(p);
535 531
536 gfx::Point offset; 532 gfx::Point offset;
537 for (const View* v = src; v; v = v->GetParent()) { 533 for (const View* v = src; v; v = v->GetParent()) {
538 offset.set_x(offset.x() + v->GetX(APPLY_MIRRORING_TRANSFORMATION)); 534 offset.set_x(offset.x() + v->GetMirroredX());
539 offset.set_y(offset.y() + v->y()); 535 offset.set_y(offset.y() + v->y());
540 } 536 }
541 p->SetPoint(p->x() + offset.x(), p->y() + offset.y()); 537 p->SetPoint(p->x() + offset.x(), p->y() + offset.y());
542 } 538 }
543 539
544 // static 540 // static
545 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) { 541 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) {
546 gfx::Point t; 542 gfx::Point t;
547 ConvertPointToWidget(dest, &t); 543 ConvertPointToWidget(dest, &t);
548 p->SetPoint(p->x() - t.x(), p->y() - t.y()); 544 p->SetPoint(p->x() - t.x(), p->y() - t.y());
(...skipping 17 matching lines...) Expand all
566 // Painting -------------------------------------------------------------------- 562 // Painting --------------------------------------------------------------------
567 563
568 void View::SchedulePaint(const gfx::Rect& r, bool urgent) { 564 void View::SchedulePaint(const gfx::Rect& r, bool urgent) {
569 if (!IsVisible()) 565 if (!IsVisible())
570 return; 566 return;
571 567
572 if (parent_) { 568 if (parent_) {
573 // Translate the requested paint rect to the parent's coordinate system 569 // Translate the requested paint rect to the parent's coordinate system
574 // then pass this notification up to the parent. 570 // then pass this notification up to the parent.
575 gfx::Rect paint_rect = r; 571 gfx::Rect paint_rect = r;
576 paint_rect.Offset(GetPosition()); 572 paint_rect.Offset(GetMirroredPosition());
577 parent_->SchedulePaint(paint_rect, urgent); 573 parent_->SchedulePaint(paint_rect, urgent);
578 } 574 }
579 } 575 }
580 576
581 void View::SchedulePaint() { 577 void View::SchedulePaint() {
582 SchedulePaint(GetContentsBounds(), false); 578 SchedulePaint(GetContentsBounds(), false);
583 } 579 }
584 580
585 void View::Paint(gfx::Canvas* canvas) { 581 void View::Paint(gfx::Canvas* canvas) {
586 PaintBackground(canvas); 582 PaintBackground(canvas);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // We're going to modify the canvas, save it's state first. 615 // We're going to modify the canvas, save it's state first.
620 canvas->Save(); 616 canvas->Save();
621 617
622 // Paint this View and its children, setting the clip rect to the bounds 618 // Paint this View and its children, setting the clip rect to the bounds
623 // of this View and translating the origin to the local bounds' top left 619 // of this View and translating the origin to the local bounds' top left
624 // point. 620 // point.
625 // 621 //
626 // Note that the X (or left) position we pass to ClipRectInt takes into 622 // Note that the X (or left) position we pass to ClipRectInt takes into
627 // consideration whether or not the view uses a right-to-left layout so that 623 // consideration whether or not the view uses a right-to-left layout so that
628 // we paint our view in its mirrored position if need be. 624 // we paint our view in its mirrored position if need be.
629 if (canvas->ClipRectInt(MirroredX(), y(), width(), height())) { 625 if (canvas->ClipRectInt(GetMirroredX(), y(), width(), height())) {
630 // Non-empty clip, translate the graphics such that 0,0 corresponds to 626 // Non-empty clip, translate the graphics such that 0,0 corresponds to
631 // where this view is located (related to its parent). 627 // where this view is located (related to its parent).
632 canvas->TranslateInt(MirroredX(), y()); 628 canvas->TranslateInt(GetMirroredX(), y());
633 629
634 // If the View we are about to paint requested the canvas to be flipped, we 630 // If the View we are about to paint requested the canvas to be flipped, we
635 // should change the transform appropriately. 631 // should change the transform appropriately.
636 canvas->Save(); 632 canvas->Save();
637 if (FlipCanvasOnPaintForRTLUI()) { 633 if (FlipCanvasOnPaintForRTLUI()) {
638 canvas->TranslateInt(width(), 0); 634 canvas->TranslateInt(width(), 0);
639 canvas->ScaleInt(-1, 1); 635 canvas->ScaleInt(-1, 1);
640 } 636 }
641 637
642 Paint(canvas); 638 Paint(canvas);
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 954
959 // Scrolling ------------------------------------------------------------------- 955 // Scrolling -------------------------------------------------------------------
960 956
961 void View::ScrollRectToVisible(const gfx::Rect& rect) { 957 void View::ScrollRectToVisible(const gfx::Rect& rect) {
962 View* parent = GetParent(); 958 View* parent = GetParent();
963 959
964 // We must take RTL UI mirroring into account when adjusting the position of 960 // We must take RTL UI mirroring into account when adjusting the position of
965 // the region. 961 // the region.
966 if (parent) { 962 if (parent) {
967 gfx::Rect scroll_rect(rect); 963 gfx::Rect scroll_rect(rect);
968 scroll_rect.Offset(GetX(APPLY_MIRRORING_TRANSFORMATION), y()); 964 scroll_rect.Offset(GetMirroredX(), y());
969 parent->ScrollRectToVisible(scroll_rect); 965 parent->ScrollRectToVisible(scroll_rect);
970 } 966 }
971 } 967 }
972 968
973 int View::GetPageScrollIncrement(ScrollView* scroll_view, 969 int View::GetPageScrollIncrement(ScrollView* scroll_view,
974 bool is_horizontal, bool is_positive) { 970 bool is_horizontal, bool is_positive) {
975 return 0; 971 return 0;
976 } 972 }
977 973
978 int View::GetLineScrollIncrement(ScrollView* scroll_view, 974 int View::GetLineScrollIncrement(ScrollView* scroll_view,
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 const View* dst, 1328 const View* dst,
1333 gfx::Point* point, 1329 gfx::Point* point,
1334 bool try_other_direction) { 1330 bool try_other_direction) {
1335 // src can be NULL 1331 // src can be NULL
1336 DCHECK(dst); 1332 DCHECK(dst);
1337 DCHECK(point); 1333 DCHECK(point);
1338 1334
1339 const View* v; 1335 const View* v;
1340 gfx::Point offset; 1336 gfx::Point offset;
1341 1337
1342 for (v = dst; v && v != src; v = v->GetParent()) { 1338 for (v = dst; v && v != src; v = v->GetParent())
1343 offset.SetPoint(offset.x() + v->GetX(APPLY_MIRRORING_TRANSFORMATION), 1339 offset.SetPoint(offset.x() + v->GetMirroredX(), offset.y() + v->y());
1344 offset.y() + v->y());
1345 }
1346 1340
1347 // The source was not found. The caller wants a conversion 1341 // The source was not found. The caller wants a conversion
1348 // from a view to a transitive parent. 1342 // from a view to a transitive parent.
1349 if (src && v == NULL && try_other_direction) { 1343 if (src && v == NULL && try_other_direction) {
1350 gfx::Point p; 1344 gfx::Point p;
1351 // note: try_other_direction is force to FALSE so we don't 1345 // note: try_other_direction is force to FALSE so we don't
1352 // end up in an infinite recursion should both src and dst 1346 // end up in an infinite recursion should both src and dst
1353 // are not parented. 1347 // are not parented.
1354 ConvertPointToView(dst, src, &p, false); 1348 ConvertPointToView(dst, src, &p, false);
1355 // since the src and dst are inverted, p should also be negated 1349 // since the src and dst are inverted, p should also be negated
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
1574 OSExchangeData data; 1568 OSExchangeData data;
1575 WriteDragData(press_pt, &data); 1569 WriteDragData(press_pt, &data);
1576 1570
1577 // Message the RootView to do the drag and drop. That way if we're removed 1571 // Message the RootView to do the drag and drop. That way if we're removed
1578 // the RootView can detect it and avoid calling us back. 1572 // the RootView can detect it and avoid calling us back.
1579 RootView* root_view = GetRootView(); 1573 RootView* root_view = GetRootView();
1580 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations); 1574 root_view->StartDragForViewFromMouseEvent(this, data, drag_operations);
1581 } 1575 }
1582 1576
1583 } // namespace views 1577 } // namespace views
OLDNEW
« no previous file with comments | « views/view.h ('k') | views/view_text_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698