Chromium Code Reviews| 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/base/ime/input_method.h" | 22 #include "ui/base/ime/input_method.h" |
| 23 #include "ui/compositor/clip_transform_recorder.h" | 23 #include "ui/compositor/clip_recorder.h" |
| 24 #include "ui/compositor/compositor.h" | 24 #include "ui/compositor/compositor.h" |
| 25 #include "ui/compositor/dip_util.h" | 25 #include "ui/compositor/dip_util.h" |
| 26 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| 27 #include "ui/compositor/layer_animator.h" | 27 #include "ui/compositor/layer_animator.h" |
| 28 #include "ui/compositor/paint_context.h" | 28 #include "ui/compositor/paint_context.h" |
| 29 #include "ui/compositor/paint_recorder.h" | 29 #include "ui/compositor/paint_recorder.h" |
| 30 #include "ui/compositor/transform_recorder.h" | |
| 30 #include "ui/events/event_target_iterator.h" | 31 #include "ui/events/event_target_iterator.h" |
| 31 #include "ui/gfx/canvas.h" | 32 #include "ui/gfx/canvas.h" |
| 32 #include "ui/gfx/geometry/point3_f.h" | 33 #include "ui/gfx/geometry/point3_f.h" |
| 33 #include "ui/gfx/geometry/point_conversions.h" | 34 #include "ui/gfx/geometry/point_conversions.h" |
| 34 #include "ui/gfx/interpolated_transform.h" | 35 #include "ui/gfx/interpolated_transform.h" |
| 35 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
| 36 #include "ui/gfx/scoped_canvas.h" | 37 #include "ui/gfx/scoped_canvas.h" |
| 37 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
| 38 #include "ui/gfx/skia_util.h" | 39 #include "ui/gfx/skia_util.h" |
| 39 #include "ui/gfx/transform.h" | 40 #include "ui/gfx/transform.h" |
| (...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 771 | 772 |
| 772 // If the View wasn't invalidated, don't waste time painting it, the output | 773 // If the View wasn't invalidated, don't waste time painting it, the output |
| 773 // would be culled. | 774 // would be culled. |
| 774 is_invalidated = context.IsRectInvalid(GetLocalBounds()); | 775 is_invalidated = context.IsRectInvalid(GetLocalBounds()); |
| 775 } | 776 } |
| 776 | 777 |
| 777 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); | 778 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); |
| 778 | 779 |
| 779 // If the view is backed by a layer, it should paint with itself as the origin | 780 // If the view is backed by a layer, it should paint with itself as the origin |
| 780 // rather than relative to its parent. | 781 // rather than relative to its parent. |
| 781 ui::ClipTransformRecorder clip_transform_recorder(context); | 782 ui::ClipRecorder clip_recorder(context); |
| 783 ui::TransformRecorder transform_recorder(context); | |
| 782 if (!layer()) { | 784 if (!layer()) { |
|
danakj
2015/11/23 23:20:30
can you refactor this just slightly. it's importan
wkorman
2015/11/23 23:38:08
Done.
| |
| 783 // Set the clip rect to the bounds of this View. Note that the X (or left) | 785 // 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 | 786 // 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 | 787 // View uses a right-to-left layout so that we paint the View in its |
| 786 // mirrored position if need be. | 788 // mirrored position if need be. |
| 787 gfx::Rect clip_rect_in_parent = bounds(); | 789 gfx::Rect clip_rect_in_parent = bounds(); |
| 788 clip_rect_in_parent.Inset(clip_insets_); | 790 clip_rect_in_parent.Inset(clip_insets_); |
| 789 if (parent_) | 791 if (parent_) |
| 790 clip_rect_in_parent.set_x( | 792 clip_rect_in_parent.set_x( |
| 791 parent_->GetMirroredXForRect(clip_rect_in_parent)); | 793 parent_->GetMirroredXForRect(clip_rect_in_parent)); |
| 792 clip_transform_recorder.ClipRect(clip_rect_in_parent); | 794 clip_recorder.ClipRect(clip_rect_in_parent); |
| 793 | 795 |
| 794 // Translate the graphics such that 0,0 corresponds to where | 796 // Translate the graphics such that 0,0 corresponds to where |
| 795 // this View is located relative to its parent. | 797 // this View is located relative to its parent. |
| 796 gfx::Transform transform_from_parent; | 798 gfx::Transform transform_from_parent; |
| 797 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin(); | 799 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin(); |
| 798 transform_from_parent.Translate(offset_from_parent.x(), | 800 transform_from_parent.Translate(offset_from_parent.x(), |
| 799 offset_from_parent.y()); | 801 offset_from_parent.y()); |
| 800 transform_from_parent.PreconcatTransform(GetTransform()); | 802 transform_from_parent.PreconcatTransform(GetTransform()); |
| 801 clip_transform_recorder.Transform(transform_from_parent); | 803 transform_recorder.Transform(transform_from_parent); |
| 802 } | 804 } |
| 803 | 805 |
| 804 if (is_invalidated || !paint_cache_.UseCache(context)) { | 806 if (is_invalidated || !paint_cache_.UseCache(context)) { |
| 805 ui::PaintRecorder recorder(context, size(), &paint_cache_); | 807 ui::PaintRecorder recorder(context, size(), &paint_cache_); |
| 806 gfx::Canvas* canvas = recorder.canvas(); | 808 gfx::Canvas* canvas = recorder.canvas(); |
| 807 | 809 |
| 808 // 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 |
| 809 // should change the transform appropriately. | 811 // should change the transform appropriately. |
| 810 // 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 |
| 811 // 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 |
| (...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2365 // Message the RootView to do the drag and drop. That way if we're removed | 2367 // Message the RootView to do the drag and drop. That way if we're removed |
| 2366 // the RootView can detect it and avoid calling us back. | 2368 // the RootView can detect it and avoid calling us back. |
| 2367 gfx::Point widget_location(event.location()); | 2369 gfx::Point widget_location(event.location()); |
| 2368 ConvertPointToWidget(this, &widget_location); | 2370 ConvertPointToWidget(this, &widget_location); |
| 2369 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2371 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2370 // WARNING: we may have been deleted. | 2372 // WARNING: we may have been deleted. |
| 2371 return true; | 2373 return true; |
| 2372 } | 2374 } |
| 2373 | 2375 |
| 2374 } // namespace views | 2376 } // namespace views |
| OLD | NEW |