OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 #include "views/border.h" | 5 #include "views/border.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gfx/canvas.h" | 8 #include "gfx/canvas.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
(...skipping 16 matching lines...) Expand all Loading... |
27 DISALLOW_COPY_AND_ASSIGN(SolidBorder); | 27 DISALLOW_COPY_AND_ASSIGN(SolidBorder); |
28 }; | 28 }; |
29 | 29 |
30 SolidBorder::SolidBorder(int thickness, SkColor color) | 30 SolidBorder::SolidBorder(int thickness, SkColor color) |
31 : thickness_(thickness), | 31 : thickness_(thickness), |
32 color_(color), | 32 color_(color), |
33 insets_(thickness, thickness, thickness, thickness) { | 33 insets_(thickness, thickness, thickness, thickness) { |
34 } | 34 } |
35 | 35 |
36 void SolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { | 36 void SolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { |
37 gfx::Rect clip_rect; | |
38 if (!canvas->GetClipRect(&clip_rect)) | |
39 return; // Empty clip rectangle, nothing to paint. | |
40 | |
41 // Top border. | 37 // Top border. |
42 gfx::Rect border_bounds(0, 0, view.width(), insets_.top()); | 38 canvas->FillRectInt(color_, 0, 0, view.width(), insets_.top()); |
43 if (clip_rect.Intersects(border_bounds)) | |
44 canvas->FillRectInt(color_, 0, 0, view.width(), insets_.top()); | |
45 // Left border. | 39 // Left border. |
46 border_bounds.SetRect(0, 0, insets_.left(), view.height()); | 40 canvas->FillRectInt(color_, 0, 0, insets_.left(), view.height()); |
47 if (clip_rect.Intersects(border_bounds)) | |
48 canvas->FillRectInt(color_, 0, 0, insets_.left(), view.height()); | |
49 // Bottom border. | 41 // Bottom border. |
50 border_bounds.SetRect(0, view.height() - insets_.bottom(), | 42 canvas->FillRectInt(color_, 0, view.height() - insets_.bottom(), |
51 view.width(), insets_.bottom()); | 43 view.width(), insets_.bottom()); |
52 if (clip_rect.Intersects(border_bounds)) | |
53 canvas->FillRectInt(color_, 0, view.height() - insets_.bottom(), | |
54 view.width(), insets_.bottom()); | |
55 // Right border. | 44 // Right border. |
56 border_bounds.SetRect(view.width() - insets_.right(), 0, | 45 canvas->FillRectInt(color_, view.width() - insets_.right(), 0, |
57 insets_.right(), view.height()); | 46 insets_.right(), view.height()); |
58 if (clip_rect.Intersects(border_bounds)) | |
59 canvas->FillRectInt(color_, view.width() - insets_.right(), 0, | |
60 insets_.right(), view.height()); | |
61 } | 47 } |
62 | 48 |
63 void SolidBorder::GetInsets(gfx::Insets* insets) const { | 49 void SolidBorder::GetInsets(gfx::Insets* insets) const { |
64 DCHECK(insets); | 50 DCHECK(insets); |
65 insets->Set(insets_.top(), insets_.left(), insets_.bottom(), insets_.right()); | 51 insets->Set(insets_.top(), insets_.left(), insets_.bottom(), insets_.right()); |
66 } | 52 } |
67 | 53 |
68 class EmptyBorder : public Border { | 54 class EmptyBorder : public Border { |
69 public: | 55 public: |
70 EmptyBorder(int top, int left, int bottom, int right) | 56 EmptyBorder(int top, int left, int bottom, int right) |
(...skipping 26 matching lines...) Expand all Loading... |
97 Border* Border::CreateSolidBorder(int thickness, SkColor color) { | 83 Border* Border::CreateSolidBorder(int thickness, SkColor color) { |
98 return new SolidBorder(thickness, color); | 84 return new SolidBorder(thickness, color); |
99 } | 85 } |
100 | 86 |
101 // static | 87 // static |
102 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { | 88 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { |
103 return new EmptyBorder(top, left, bottom, right); | 89 return new EmptyBorder(top, left, bottom, right); |
104 } | 90 } |
105 | 91 |
106 } // namespace views | 92 } // namespace views |
OLD | NEW |