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