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 781 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 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2128 gfx::Point widget_location(event.location()); | 2126 gfx::Point widget_location(event.location()); |
2129 ConvertPointToWidget(this, &widget_location); | 2127 ConvertPointToWidget(this, &widget_location); |
2130 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); | 2128 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations); |
2131 return true; | 2129 return true; |
2132 #else | 2130 #else |
2133 return false; | 2131 return false; |
2134 #endif // !defined(OS_MACOSX) | 2132 #endif // !defined(OS_MACOSX) |
2135 } | 2133 } |
2136 | 2134 |
2137 } // namespace views | 2135 } // namespace views |
OLD | NEW |