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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. | 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. |
6 | 6 |
7 #include "ui/views/view.h" | 7 #include "ui/views/view.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
11 | 11 |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/stringprintf.h" | 17 #include "base/stringprintf.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "third_party/skia/include/core/SkRect.h" | 19 #include "third_party/skia/include/core/SkRect.h" |
20 #include "ui/base/accessibility/accessibility_types.h" | 20 #include "ui/base/accessibility/accessibility_types.h" |
21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
22 #include "ui/base/ui_base_switches.h" | 22 #include "ui/base/ui_base_switches.h" |
| 23 #include "ui/base/win/dpi.h" |
23 #include "ui/compositor/compositor.h" | 24 #include "ui/compositor/compositor.h" |
24 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
25 #include "ui/compositor/layer_animator.h" | 26 #include "ui/compositor/layer_animator.h" |
26 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
27 #include "ui/gfx/interpolated_transform.h" | 28 #include "ui/gfx/interpolated_transform.h" |
28 #include "ui/gfx/path.h" | 29 #include "ui/gfx/path.h" |
29 #include "ui/gfx/point3_f.h" | 30 #include "ui/gfx/point3_f.h" |
30 #include "ui/gfx/point_conversions.h" | 31 #include "ui/gfx/point_conversions.h" |
31 #include "ui/gfx/rect_conversions.h" | 32 #include "ui/gfx/rect_conversions.h" |
32 #include "ui/gfx/skia_util.h" | 33 #include "ui/gfx/skia_util.h" |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 // static | 659 // static |
659 void View::ConvertPointToScreen(const View* src, gfx::Point* p) { | 660 void View::ConvertPointToScreen(const View* src, gfx::Point* p) { |
660 DCHECK(src); | 661 DCHECK(src); |
661 DCHECK(p); | 662 DCHECK(p); |
662 | 663 |
663 // If the view is not connected to a tree, there's nothing we can do. | 664 // If the view is not connected to a tree, there's nothing we can do. |
664 const Widget* widget = src->GetWidget(); | 665 const Widget* widget = src->GetWidget(); |
665 if (widget) { | 666 if (widget) { |
666 ConvertPointToWidget(src, p); | 667 ConvertPointToWidget(src, p); |
667 *p += widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); | 668 *p += widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
| 669 #if defined(ENABLE_HIDPI) |
| 670 static float dpi_scale = ui::GetDPIScale(); |
| 671 p->set_x(p->x()*dpi_scale); |
| 672 p->set_y(p->y()*dpi_scale); |
| 673 #endif |
668 } | 674 } |
669 } | 675 } |
670 | 676 |
671 // static | 677 // static |
672 void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) { | 678 void View::ConvertPointFromScreen(const View* dst, gfx::Point* p) { |
673 DCHECK(dst); | 679 DCHECK(dst); |
674 DCHECK(p); | 680 DCHECK(p); |
675 | 681 |
676 const views::Widget* widget = dst->GetWidget(); | 682 const views::Widget* widget = dst->GetWidget(); |
677 if (!widget) | 683 if (!widget) |
678 return; | 684 return; |
| 685 #if defined(ENABLE_HIDPI) |
| 686 static float dpi_scale = ui::GetDPIScale(); |
| 687 p->set_x(p->x()/dpi_scale); |
| 688 p->set_y(p->y()/dpi_scale); |
| 689 #endif |
679 *p -= widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); | 690 *p -= widget->GetClientAreaBoundsInScreen().OffsetFromOrigin(); |
680 views::View::ConvertPointFromWidget(dst, p); | 691 views::View::ConvertPointFromWidget(dst, p); |
681 } | 692 } |
682 | 693 |
683 gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { | 694 gfx::Rect View::ConvertRectToParent(const gfx::Rect& rect) const { |
684 gfx::RectF x_rect = rect; | 695 gfx::RectF x_rect = rect; |
685 GetTransform().TransformRect(&x_rect); | 696 GetTransform().TransformRect(&x_rect); |
686 x_rect.Offset(GetMirroredPosition().OffsetFromOrigin()); | 697 x_rect.Offset(GetMirroredPosition().OffsetFromOrigin()); |
687 // Pixels we partially occupy in the parent should be included. | 698 // Pixels we partially occupy in the parent should be included. |
688 return gfx::ToEnclosingRect(x_rect); | 699 return gfx::ToEnclosingRect(x_rect); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 // we paint our view in its mirrored position if need be. | 739 // we paint our view in its mirrored position if need be. |
729 gfx::Rect clip_rect = bounds(); | 740 gfx::Rect clip_rect = bounds(); |
730 clip_rect.Inset(clip_insets_); | 741 clip_rect.Inset(clip_insets_); |
731 if (parent_) | 742 if (parent_) |
732 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); | 743 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); |
733 if (!canvas->ClipRect(clip_rect)) | 744 if (!canvas->ClipRect(clip_rect)) |
734 return; | 745 return; |
735 | 746 |
736 // Non-empty clip, translate the graphics such that 0,0 corresponds to | 747 // Non-empty clip, translate the graphics such that 0,0 corresponds to |
737 // where this view is located (related to its parent). | 748 // where this view is located (related to its parent). |
| 749 static float scale = ui::GetDPIScale(); |
| 750 //canvas->Scale(scale,scale); |
| 751 //canvas->Scale(1.0,1.0); |
738 canvas->Translate(GetMirroredPosition().OffsetFromOrigin()); | 752 canvas->Translate(GetMirroredPosition().OffsetFromOrigin()); |
739 canvas->Transform(GetTransform()); | 753 canvas->Transform(GetTransform()); |
740 | 754 |
741 PaintCommon(canvas); | 755 PaintCommon(canvas); |
742 } | 756 } |
743 | 757 |
744 ui::ThemeProvider* View::GetThemeProvider() const { | 758 ui::ThemeProvider* View::GetThemeProvider() const { |
745 const Widget* widget = GetWidget(); | 759 const Widget* widget = GetWidget(); |
746 return widget ? widget->GetThemeProvider() : NULL; | 760 return widget ? widget->GetThemeProvider() : NULL; |
747 } | 761 } |
748 | 762 |
749 const ui::NativeTheme* View::GetNativeTheme() const { | 763 const ui::NativeTheme* View::GetNativeTheme() const { |
750 const Widget* widget = GetWidget(); | 764 const Widget* widget = GetWidget(); |
751 return widget ? widget->GetNativeTheme() : ui::NativeTheme::instance(); | 765 return widget ? widget->GetNativeTheme() : ui::NativeTheme::instance(); |
752 } | 766 } |
753 | 767 |
754 // Accelerated Painting -------------------------------------------------------- | 768 // Accelerated Painting -------------------------------------------------------- |
755 | 769 |
756 // static | 770 // static |
757 void View::set_use_acceleration_when_possible(bool use) { | 771 void View::set_use_acceleration_when_possible(bool use) { |
758 use_acceleration_when_possible = use; | 772 use_acceleration_when_possible = use; |
759 } | 773 } |
760 | 774 |
761 // static | 775 // static |
762 bool View::get_use_acceleration_when_possible() { | 776 bool View::get_use_acceleration_when_possible() { |
763 return use_acceleration_when_possible; | 777 return use_acceleration_when_possible; |
764 } | 778 } |
765 | 779 |
766 // Input ----------------------------------------------------------------------- | 780 // Input ----------------------------------------------------------------------- |
| 781 void ScalePoint(gfx::Point* point) { |
| 782 static float os_scale = ui::GetDPIScale(); |
| 783 point->set_x( point->x() / os_scale); |
| 784 point->set_y( point->y() / os_scale); |
| 785 } |
767 | 786 |
768 View* View::GetEventHandlerForPoint(const gfx::Point& point) { | 787 View* View::GetEventHandlerForPoint(const gfx::Point& point) { |
769 // Walk the child Views recursively looking for the View that most | 788 // Walk the child Views recursively looking for the View that most |
770 // tightly encloses the specified point. | 789 // tightly encloses the specified point. |
771 for (int i = child_count() - 1; i >= 0; --i) { | 790 for (int i = child_count() - 1; i >= 0; --i) { |
772 View* child = child_at(i); | 791 View* child = child_at(i); |
773 if (!child->visible()) | 792 if (!child->visible()) |
774 continue; | 793 continue; |
775 | 794 |
776 gfx::Point point_in_child_coords(point); | 795 gfx::Point point_in_child_coords(point); |
777 ConvertPointToTarget(this, child, &point_in_child_coords); | 796 ConvertPointToTarget(this, child, &point_in_child_coords); |
778 if (child->HitTestPoint(point_in_child_coords)) | 797 gfx::Point point_in_real_coords(point_in_child_coords); |
| 798 ScalePoint(&point_in_real_coords); |
| 799 if (child->HitTestPoint(point_in_real_coords)) |
779 return child->GetEventHandlerForPoint(point_in_child_coords); | 800 return child->GetEventHandlerForPoint(point_in_child_coords); |
780 } | 801 } |
781 return this; | 802 return this; |
782 } | 803 } |
783 | 804 |
784 gfx::NativeCursor View::GetCursor(const ui::MouseEvent& event) { | 805 gfx::NativeCursor View::GetCursor(const ui::MouseEvent& event) { |
785 #if defined(OS_WIN) | 806 #if defined(OS_WIN) |
786 #if defined(USE_AURA) | 807 #if defined(USE_AURA) |
787 static ui::Cursor arrow; | 808 static ui::Cursor arrow; |
788 if (!arrow.platform()) | 809 if (!arrow.platform()) |
(...skipping 1373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2162 ConvertPointToWidget(this, &widget_location); | 2183 ConvertPointToWidget(this, &widget_location); |
2163 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, | 2184 GetWidget()->RunShellDrag(this, data, widget_location, drag_operations, |
2164 source); | 2185 source); |
2165 return true; | 2186 return true; |
2166 #else | 2187 #else |
2167 return false; | 2188 return false; |
2168 #endif // !defined(OS_MACOSX) | 2189 #endif // !defined(OS_MACOSX) |
2169 } | 2190 } |
2170 | 2191 |
2171 } // namespace views | 2192 } // namespace views |
OLD | NEW |