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/logging.h" | 12 #include "base/logging.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "base/trace_event/trace_event.h" | 17 #include "base/trace_event/trace_event.h" |
18 #include "third_party/skia/include/core/SkRect.h" | 18 #include "third_party/skia/include/core/SkRect.h" |
19 #include "ui/accessibility/ax_enums.h" | 19 #include "ui/accessibility/ax_enums.h" |
20 #include "ui/base/cursor/cursor.h" | 20 #include "ui/base/cursor/cursor.h" |
21 #include "ui/base/dragdrop/drag_drop_types.h" | 21 #include "ui/base/dragdrop/drag_drop_types.h" |
| 22 #include "ui/compositor/clip_transform_recorder.h" |
22 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
23 #include "ui/compositor/dip_util.h" | 24 #include "ui/compositor/dip_util.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/compositor/paint_context.h" | 27 #include "ui/compositor/paint_context.h" |
| 28 #include "ui/compositor/paint_recorder.h" |
27 #include "ui/events/event_target_iterator.h" | 29 #include "ui/events/event_target_iterator.h" |
28 #include "ui/gfx/canvas.h" | 30 #include "ui/gfx/canvas.h" |
29 #include "ui/gfx/geometry/point3_f.h" | 31 #include "ui/gfx/geometry/point3_f.h" |
30 #include "ui/gfx/geometry/point_conversions.h" | 32 #include "ui/gfx/geometry/point_conversions.h" |
31 #include "ui/gfx/interpolated_transform.h" | 33 #include "ui/gfx/interpolated_transform.h" |
32 #include "ui/gfx/path.h" | 34 #include "ui/gfx/path.h" |
33 #include "ui/gfx/scoped_canvas.h" | 35 #include "ui/gfx/scoped_canvas.h" |
34 #include "ui/gfx/screen.h" | 36 #include "ui/gfx/screen.h" |
35 #include "ui/gfx/skia_util.h" | 37 #include "ui/gfx/skia_util.h" |
36 #include "ui/gfx/transform.h" | 38 #include "ui/gfx/transform.h" |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
767 #endif | 769 #endif |
768 | 770 |
769 // If the View wasn't invalidated, don't waste time painting it, the output | 771 // If the View wasn't invalidated, don't waste time painting it, the output |
770 // would be culled. | 772 // would be culled. |
771 if (!context.IsRectInvalidated(GetLocalBounds())) | 773 if (!context.IsRectInvalidated(GetLocalBounds())) |
772 return; | 774 return; |
773 } | 775 } |
774 | 776 |
775 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); | 777 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); |
776 | 778 |
777 gfx::Canvas* canvas = context.canvas(); | |
778 gfx::ScopedCanvas scoped_canvas(canvas); | |
779 | |
780 // If the view is backed by a layer, it should paint with itself as the origin | 779 // If the view is backed by a layer, it should paint with itself as the origin |
781 // rather than relative to its parent. | 780 // rather than relative to its parent. |
| 781 scoped_ptr<ui::ClipTransformRecorder> clip_transform_recorder; |
782 if (!layer()) { | 782 if (!layer()) { |
783 // Set the clip rect to the bounds of this View. Note that the X (or left) | 783 // Set the clip rect to the bounds of this View. Note that the X (or left) |
784 // position we pass to ClipRect takes into consideration whether or not the | 784 // position we pass to ClipRect takes into consideration whether or not the |
785 // View uses a right-to-left layout so that we paint the View in its | 785 // View uses a right-to-left layout so that we paint the View in its |
786 // mirrored position if need be. | 786 // mirrored position if need be. |
787 gfx::Rect clip_rect = bounds(); | 787 gfx::Rect clip_rect_in_parent = bounds(); |
788 clip_rect.Inset(clip_insets_); | 788 clip_rect_in_parent.Inset(clip_insets_); |
789 if (parent_) | 789 if (parent_) |
790 clip_rect.set_x(parent_->GetMirroredXForRect(clip_rect)); | 790 clip_rect_in_parent.set_x( |
791 canvas->ClipRect(clip_rect); | 791 parent_->GetMirroredXForRect(clip_rect_in_parent)); |
792 | 792 |
793 // Translate the graphics such that 0,0 corresponds to where | 793 // Translate the graphics such that 0,0 corresponds to where |
794 // this View is located relative to its parent. | 794 // this View is located relative to its parent. |
795 canvas->Translate(GetMirroredPosition().OffsetFromOrigin()); | 795 gfx::Transform transform_from_parent; |
796 canvas->Transform(GetTransform()); | 796 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin(); |
| 797 transform_from_parent.Translate(offset_from_parent.x(), |
| 798 offset_from_parent.y()); |
| 799 transform_from_parent.PreconcatTransform(GetTransform()); |
| 800 |
| 801 clip_transform_recorder = make_scoped_ptr(new ui::ClipTransformRecorder( |
| 802 context, clip_rect_in_parent, transform_from_parent)); |
797 } | 803 } |
798 | 804 |
799 { | 805 { |
| 806 ui::PaintRecorder recorder(context); |
| 807 gfx::Canvas* canvas = recorder.canvas(); |
| 808 gfx::ScopedCanvas scoped_canvas(canvas); |
| 809 |
800 // If the View we are about to paint requested the canvas to be flipped, we | 810 // If the View we are about to paint requested the canvas to be flipped, we |
801 // should change the transform appropriately. | 811 // should change the transform appropriately. |
802 // The canvas mirroring is undone once the View is done painting so that we | 812 // The canvas mirroring is undone once the View is done painting so that we |
803 // don't pass the canvas with the mirrored transform to Views that didn't | 813 // don't pass the canvas with the mirrored transform to Views that didn't |
804 // request the canvas to be flipped. | 814 // request the canvas to be flipped. |
805 gfx::ScopedCanvas scoped(canvas); | |
806 if (FlipCanvasOnPaintForRTLUI()) { | 815 if (FlipCanvasOnPaintForRTLUI()) { |
807 canvas->Translate(gfx::Vector2d(width(), 0)); | 816 canvas->Translate(gfx::Vector2d(width(), 0)); |
808 canvas->Scale(-1, 1); | 817 canvas->Scale(-1, 1); |
809 } | 818 } |
810 | 819 |
811 // Delegate painting the contents of the View to the virtual OnPaint method. | 820 // Delegate painting the contents of the View to the virtual OnPaint method. |
812 OnPaint(canvas); | 821 OnPaint(canvas); |
813 } | 822 } |
814 | 823 |
| 824 // View::Paint() recursion over the subtree. |
815 PaintChildren(context); | 825 PaintChildren(context); |
816 } | 826 } |
817 | 827 |
818 void View::set_background(Background* b) { | 828 void View::set_background(Background* b) { |
819 background_.reset(b); | 829 background_.reset(b); |
820 } | 830 } |
821 | 831 |
822 void View::SetBorder(scoped_ptr<Border> b) { border_ = b.Pass(); } | 832 void View::SetBorder(scoped_ptr<Border> b) { border_ = b.Pass(); } |
823 | 833 |
824 ui::ThemeProvider* View::GetThemeProvider() const { | 834 ui::ThemeProvider* View::GetThemeProvider() const { |
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 // Message the RootView to do the drag and drop. That way if we're removed | 2366 // Message the RootView to do the drag and drop. That way if we're removed |
2357 // the RootView can detect it and avoid calling us back. | 2367 // the RootView can detect it and avoid calling us back. |
2358 gfx::Point widget_location(event.location()); | 2368 gfx::Point widget_location(event.location()); |
2359 ConvertPointToWidget(this, &widget_location); | 2369 ConvertPointToWidget(this, &widget_location); |
2360 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2370 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
2361 // WARNING: we may have been deleted. | 2371 // WARNING: we may have been deleted. |
2362 return true; | 2372 return true; |
2363 } | 2373 } |
2364 | 2374 |
2365 } // namespace views | 2375 } // namespace views |
OLD | NEW |