Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: ui/views/view.cc

Issue 1423653005: Further plumb visual rect into cc:DisplayItemList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix clip recorder params in omnibox. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/compositor/transform_recorder.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 // would be culled. 774 // would be culled.
775 is_invalidated = context.IsRectInvalid(GetLocalBounds()); 775 is_invalidated = context.IsRectInvalid(GetLocalBounds());
776 } 776 }
777 777
778 TRACE_EVENT1("views", "View::Paint", "class", GetClassName()); 778 TRACE_EVENT1("views", "View::Paint", "class", GetClassName());
779 779
780 // 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
781 // rather than relative to its parent. 781 // rather than relative to its parent.
782 bool paint_relative_to_parent = !layer(); 782 bool paint_relative_to_parent = !layer();
783 783
784 ui::ClipRecorder clip_recorder(context); 784 // TODO(wkorman): Rework clip and transform recorders to pass the size in the
785 // individual clip methods rather than in the constructor.
786 ui::ClipRecorder clip_recorder(parent_context,
787 parent() ? parent()->size() : size());
785 if (paint_relative_to_parent) { 788 if (paint_relative_to_parent) {
786 // Set the clip rect to the bounds of this View. Note that the X (or left) 789 // Set the clip rect to the bounds of this View. Note that the X (or left)
787 // position we pass to ClipRect takes into consideration whether or not the 790 // position we pass to ClipRect takes into consideration whether or not the
788 // View uses a right-to-left layout so that we paint the View in its 791 // View uses a right-to-left layout so that we paint the View in its
789 // mirrored position if need be. 792 // mirrored position if need be.
790 gfx::Rect clip_rect_in_parent = bounds(); 793 gfx::Rect clip_rect_in_parent = bounds();
791 clip_rect_in_parent.Inset(clip_insets_); 794 clip_rect_in_parent.Inset(clip_insets_);
792 if (parent_) 795 if (parent_)
793 clip_rect_in_parent.set_x( 796 clip_rect_in_parent.set_x(
794 parent_->GetMirroredXForRect(clip_rect_in_parent)); 797 parent_->GetMirroredXForRect(clip_rect_in_parent));
795 clip_recorder.ClipRect(clip_rect_in_parent); 798 clip_recorder.ClipRect(clip_rect_in_parent);
796 } 799 }
797 800
798 ui::TransformRecorder transform_recorder(context); 801 ui::TransformRecorder transform_recorder(context, size());
799 if (paint_relative_to_parent) { 802 if (paint_relative_to_parent) {
800 // Translate the graphics such that 0,0 corresponds to where 803 // Translate the graphics such that 0,0 corresponds to where
801 // this View is located relative to its parent. 804 // this View is located relative to its parent.
802 gfx::Transform transform_from_parent; 805 gfx::Transform transform_from_parent;
803 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin(); 806 gfx::Vector2d offset_from_parent = GetMirroredPosition().OffsetFromOrigin();
804 transform_from_parent.Translate(offset_from_parent.x(), 807 transform_from_parent.Translate(offset_from_parent.x(),
805 offset_from_parent.y()); 808 offset_from_parent.y());
806 transform_from_parent.PreconcatTransform(GetTransform()); 809 transform_from_parent.PreconcatTransform(GetTransform());
807 transform_recorder.Transform(transform_from_parent); 810 transform_recorder.Transform(transform_from_parent);
808 } 811 }
809 812
810 if (is_invalidated || !paint_cache_.UseCache(context)) { 813 // Note that the cache is not aware of the offset of the view
814 // relative to the parent since painting is always done relative to
815 // the top left of the individual view.
816 if (is_invalidated || !paint_cache_.UseCache(context, size())) {
811 ui::PaintRecorder recorder(context, size(), &paint_cache_); 817 ui::PaintRecorder recorder(context, size(), &paint_cache_);
812 gfx::Canvas* canvas = recorder.canvas(); 818 gfx::Canvas* canvas = recorder.canvas();
813 819
814 // If the View we are about to paint requested the canvas to be flipped, we 820 // If the View we are about to paint requested the canvas to be flipped, we
815 // should change the transform appropriately. 821 // should change the transform appropriately.
816 // The canvas mirroring is undone once the View is done painting so that we 822 // The canvas mirroring is undone once the View is done painting so that we
817 // don't pass the canvas with the mirrored transform to Views that didn't 823 // don't pass the canvas with the mirrored transform to Views that didn't
818 // request the canvas to be flipped. 824 // request the canvas to be flipped.
819 if (FlipCanvasOnPaintForRTLUI()) { 825 if (FlipCanvasOnPaintForRTLUI()) {
820 canvas->Translate(gfx::Vector2d(width(), 0)); 826 canvas->Translate(gfx::Vector2d(width(), 0));
(...skipping 1550 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 // Message the RootView to do the drag and drop. That way if we're removed 2377 // Message the RootView to do the drag and drop. That way if we're removed
2372 // the RootView can detect it and avoid calling us back. 2378 // the RootView can detect it and avoid calling us back.
2373 gfx::Point widget_location(event.location()); 2379 gfx::Point widget_location(event.location());
2374 ConvertPointToWidget(this, &widget_location); 2380 ConvertPointToWidget(this, &widget_location);
2375 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2381 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2376 // WARNING: we may have been deleted. 2382 // WARNING: we may have been deleted.
2377 return true; 2383 return true;
2378 } 2384 }
2379 2385
2380 } // namespace views 2386 } // namespace views
OLDNEW
« no previous file with comments | « ui/compositor/transform_recorder.cc ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698