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

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

Issue 11269022: Add Vector2d classes that represent offsets, instead of using Point. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RenderText fixup Created 8 years, 1 month 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 #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 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 if (source != root) 617 if (source != root)
618 source->ConvertPointForAncestor(root, point); 618 source->ConvertPointForAncestor(root, point);
619 } 619 }
620 620
621 if (target != root) 621 if (target != root)
622 target->ConvertPointFromAncestor(root, point); 622 target->ConvertPointFromAncestor(root, point);
623 623
624 // API defines NULL |source| as returning the point in screen coordinates. 624 // API defines NULL |source| as returning the point in screen coordinates.
625 if (!source) { 625 if (!source) {
626 *point = point->Subtract( 626 *point = point->Subtract(
627 root->GetWidget()->GetClientAreaBoundsInScreen().origin()); 627 root->GetWidget()->GetClientAreaBoundsInScreen().OffsetFromOrigin());
628 } 628 }
629 } 629 }
630 630
631 // static 631 // static
632 void View::ConvertPointToWidget(const View* src, gfx::Point* p) { 632 void View::ConvertPointToWidget(const View* src, gfx::Point* p) {
633 DCHECK(src); 633 DCHECK(src);
634 DCHECK(p); 634 DCHECK(p);
635 635
636 src->ConvertPointForAncestor(NULL, p); 636 src->ConvertPointForAncestor(NULL, p);
637 } 637 }
638 638
639 // static 639 // static
640 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) { 640 void View::ConvertPointFromWidget(const View* dest, gfx::Point* p) {
641 DCHECK(dest); 641 DCHECK(dest);
642 DCHECK(p); 642 DCHECK(p);
643 643
644 dest->ConvertPointFromAncestor(NULL, p); 644 dest->ConvertPointFromAncestor(NULL, p);
645 } 645 }
646 646
647 // static 647 // static
648 void View::ConvertPointToScreen(const View* src, gfx::Point* p) { 648 void View::ConvertPointToScreen(const View* src, gfx::Point* p) {
649 DCHECK(src); 649 DCHECK(src);
650 DCHECK(p); 650 DCHECK(p);
651 651
652 // If the view is not connected to a tree, there's nothing we can do. 652 // If the view is not connected to a tree, there's nothing we can do.
653 const Widget* widget = src->GetWidget(); 653 const Widget* widget = src->GetWidget();
654 if (widget) { 654 if (widget) {
655 ConvertPointToWidget(src, p); 655 ConvertPointToWidget(src, p);
656 gfx::Rect r = widget->GetClientAreaBoundsInScreen(); 656 *p = p->Add(widget->GetClientAreaBoundsInScreen().OffsetFromOrigin());
657 p->SetPoint(p->x() + r.x(), p->y() + r.y());
658 } 657 }
659 } 658 }
660 659
661 // static 660 // static
662 void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) { 661 void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) {
663 DCHECK(dst); 662 DCHECK(dst);
664 DCHECK(p); 663 DCHECK(p);
665 664
666 const views::Widget* widget = dst->GetWidget(); 665 const views::Widget* widget = dst->GetWidget();
667 if (!widget) 666 if (!widget)
668 return; 667 return;
669 const gfx::Rect r = widget->GetClientAreaBoundsInScreen(); 668 *p = p->Add(-widget->GetClientAreaBoundsInScreen().OffsetFromOrigin());
670 p->Offset(-r.x(), -r.y());
671 views::View::ConvertPointFromWidget(dst, p); 669 views::View::ConvertPointFromWidget(dst, p);
672 } 670 }
673 671
674 gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { 672 gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const {
675 gfx::Rect x_rect = rect; 673 gfx::Rect x_rect = rect;
676 GetTransform().TransformRect(&x_rect); 674 GetTransform().TransformRect(&x_rect);
677 x_rect.Offset(GetMirroredPosition()); 675 x_rect.Offset(GetMirroredPosition().OffsetFromOrigin());
678 return x_rect; 676 return x_rect;
679 } 677 }
680 678
681 gfx::Rect View::ConvertRectToWidget(const gfx::Rect& rect) const { 679 gfx::Rect View::ConvertRectToWidget(const gfx::Rect& rect) const {
682 gfx::Rect x_rect = rect; 680 gfx::Rect x_rect = rect;
683 for (const View* v = this; v; v = v->parent_) 681 for (const View* v = this; v; v = v->parent_)
684 x_rect = v->ConvertRectToParent(x_rect); 682 x_rect = v->ConvertRectToParent(x_rect);
685 return x_rect; 683 return x_rect;
686 } 684 }
687 685
(...skipping 30 matching lines...) Expand all
718 // we paint our view in its mirrored position if need be. 716 // we paint our view in its mirrored position if need be.
719 gfx::Rect clip_rect = bounds(); 717 gfx::Rect clip_rect = bounds();
720 clip_rect.Inset(clip_insets_); 718 clip_rect.Inset(clip_insets_);
721 if (parent_) 719 if (parent_)
722 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); 720 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect));
723 if (!canvas->ClipRect(clip_rect)) 721 if (!canvas->ClipRect(clip_rect))
724 return; 722 return;
725 723
726 // Non-empty clip, translate the graphics such that 0,0 corresponds to 724 // Non-empty clip, translate the graphics such that 0,0 corresponds to
727 // where this view is located (related to its parent). 725 // where this view is located (related to its parent).
728 canvas->Translate(GetMirroredPosition()); 726 canvas->Translate(GetMirroredPosition().OffsetFromOrigin());
729 canvas->Transform(GetTransform()); 727 canvas->Transform(GetTransform());
730 728
731 PaintCommon(canvas); 729 PaintCommon(canvas);
732 } 730 }
733 731
734 ui::ThemeProvider* View::GetThemeProvider() const { 732 ui::ThemeProvider* View::GetThemeProvider() const {
735 const Widget* widget = GetWidget(); 733 const Widget* widget = GetWidget();
736 return widget ? widget->GetThemeProvider() : NULL; 734 return widget ? widget->GetThemeProvider() : NULL;
737 } 735 }
738 736
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 } 1032 }
1035 1033
1036 int View::OnPerformDrop(const ui::DropTargetEvent& event) { 1034 int View::OnPerformDrop(const ui::DropTargetEvent& event) {
1037 return ui::DragDropTypes::DRAG_NONE; 1035 return ui::DragDropTypes::DRAG_NONE;
1038 } 1036 }
1039 1037
1040 void View::OnDragDone() { 1038 void View::OnDragDone() {
1041 } 1039 }
1042 1040
1043 // static 1041 // static
1044 bool View::ExceededDragThreshold(int delta_x, int delta_y) { 1042 bool View::ExceededDragThreshold(const gfx::Vector2d& delta) {
1045 return (abs(delta_x) > GetHorizontalDragThreshold() || 1043 return (abs(delta.x()) > GetHorizontalDragThreshold() ||
1046 abs(delta_y) > GetVerticalDragThreshold()); 1044 abs(delta.y()) > GetVerticalDragThreshold());
1047 } 1045 }
1048 1046
1049 // Scrolling ------------------------------------------------------------------- 1047 // Scrolling -------------------------------------------------------------------
1050 1048
1051 void View::ScrollRectToVisible(const gfx::Rect& rect) { 1049 void View::ScrollRectToVisible(const gfx::Rect& rect) {
1052 // We must take RTL UI mirroring into account when adjusting the position of 1050 // We must take RTL UI mirroring into account when adjusting the position of
1053 // the region. 1051 // the region.
1054 if (parent_) { 1052 if (parent_) {
1055 gfx::Rect scroll_rect(rect); 1053 gfx::Rect scroll_rect(rect);
1056 scroll_rect.Offset(GetMirroredX(), y()); 1054 scroll_rect.Offset(GetMirroredX(), y());
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 return; 1518 return;
1521 1519
1522 { 1520 {
1523 // If the View we are about to paint requested the canvas to be flipped, we 1521 // If the View we are about to paint requested the canvas to be flipped, we
1524 // should change the transform appropriately. 1522 // should change the transform appropriately.
1525 // The canvas mirroring is undone once the View is done painting so that we 1523 // The canvas mirroring is undone once the View is done painting so that we
1526 // don't pass the canvas with the mirrored transform to Views that didn't 1524 // don't pass the canvas with the mirrored transform to Views that didn't
1527 // request the canvas to be flipped. 1525 // request the canvas to be flipped.
1528 ScopedCanvas scoped(canvas); 1526 ScopedCanvas scoped(canvas);
1529 if (FlipCanvasOnPaintForRTLUI()) { 1527 if (FlipCanvasOnPaintForRTLUI()) {
1530 canvas->Translate(gfx::Point(width(), 0)); 1528 canvas->Translate(gfx::Vector2d(width(), 0));
1531 canvas->Scale(-1, 1); 1529 canvas->Scale(-1, 1);
1532 } 1530 }
1533 1531
1534 OnPaint(canvas); 1532 OnPaint(canvas);
1535 } 1533 }
1536 1534
1537 PaintChildren(canvas); 1535 PaintChildren(canvas);
1538 } 1536 }
1539 1537
1540 // Tree operations ------------------------------------------------------------- 1538 // Tree operations -------------------------------------------------------------
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 } 1930 }
1933 return !!context_menu_controller || result; 1931 return !!context_menu_controller || result;
1934 } 1932 }
1935 1933
1936 bool View::ProcessMouseDragged(const ui::MouseEvent& event, 1934 bool View::ProcessMouseDragged(const ui::MouseEvent& event,
1937 DragInfo* drag_info) { 1935 DragInfo* drag_info) {
1938 // Copy the field, that way if we're deleted after drag and drop no harm is 1936 // Copy the field, that way if we're deleted after drag and drop no harm is
1939 // done. 1937 // done.
1940 ContextMenuController* context_menu_controller = context_menu_controller_; 1938 ContextMenuController* context_menu_controller = context_menu_controller_;
1941 const bool possible_drag = drag_info->possible_drag; 1939 const bool possible_drag = drag_info->possible_drag;
1942 if (possible_drag && ExceededDragThreshold( 1940 if (possible_drag &&
1943 drag_info->start_pt.x() - event.x(), 1941 ExceededDragThreshold(drag_info->start_pt - event.location())) {
1944 drag_info->start_pt.y() - event.y())) {
1945 if (!drag_controller_ || 1942 if (!drag_controller_ ||
1946 drag_controller_->CanStartDragForView( 1943 drag_controller_->CanStartDragForView(
1947 this, drag_info->start_pt, event.location())) 1944 this, drag_info->start_pt, event.location()))
1948 DoDrag(event, drag_info->start_pt); 1945 DoDrag(event, drag_info->start_pt);
1949 } else { 1946 } else {
1950 if (OnMouseDragged(event)) 1947 if (OnMouseDragged(event))
1951 return true; 1948 return true;
1952 // Fall through to return value based on context menu controller. 1949 // Fall through to return value based on context menu controller.
1953 } 1950 }
1954 // WARNING: we may have been deleted. 1951 // WARNING: we may have been deleted.
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
2129 gfx::Point widget_location(event.location()); 2126 gfx::Point widget_location(event.location());
2130 ConvertPointToWidget(this, &widget_location); 2127 ConvertPointToWidget(this, &widget_location);
2131 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); 2128 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations);
2132 return true; 2129 return true;
2133 #else 2130 #else
2134 return false; 2131 return false;
2135 #endif // !defined(OS_MACOSX) 2132 #endif // !defined(OS_MACOSX)
2136 } 2133 }
2137 2134
2138 } // namespace views 2135 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698