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