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 "chrome/app/theme/theme_resources.h" | 5 #include "chrome/app/theme/theme_resources.h" |
6 #include "chrome/browser/views/info_bar_item_view.h" | 6 #include "chrome/browser/views/info_bar_item_view.h" |
7 #include "chrome/browser/views/standard_layout.h" | 7 #include "chrome/browser/views/standard_layout.h" |
8 #include "chrome/common/l10n_util.h" | 8 #include "chrome/common/l10n_util.h" |
9 #include "chrome/common/resource_bundle.h" | 9 #include "chrome/common/resource_bundle.h" |
10 #include "chrome/views/external_focus_tracker.h" | 10 #include "chrome/views/external_focus_tracker.h" |
11 #include "chrome/views/image_view.h" | 11 #include "chrome/views/image_view.h" |
12 #include "chrome/views/root_view.h" | 12 #include "chrome/views/root_view.h" |
13 #include "chrome/views/view_container.h" | 13 #include "chrome/views/view_container.h" |
14 | 14 |
15 #include "generated_resources.h" | 15 #include "generated_resources.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class HorizontalSpacer : public ChromeViews::View { | 19 class HorizontalSpacer : public ChromeViews::View { |
20 public: | 20 public: |
21 explicit HorizontalSpacer(int width) : width_(width) {} | 21 explicit HorizontalSpacer(int width) : width_(width) {} |
22 | 22 |
23 void GetPreferredSize(CSize* out) { | 23 gfx::Size GetPreferredSize() { |
24 out->cx = width_; | 24 return gfx::Size(width_, 0); |
25 out->cy = 0; | |
26 } | 25 } |
27 | 26 |
28 private: | 27 private: |
29 int width_; | 28 int width_; |
30 }; | 29 }; |
31 | 30 |
32 const int kInfoBarVerticalSpacing = 3; | 31 const int kInfoBarVerticalSpacing = 3; |
33 const int kInfoBarLeftMargin = 3; | 32 const int kInfoBarLeftMargin = 3; |
34 const double kInfoBarHeight = 37.0; | 33 const double kInfoBarHeight = 37.0; |
35 | 34 |
36 } // namespace | 35 } // namespace |
37 | 36 |
38 InfoBarItemView::InfoBarItemView() | 37 InfoBarItemView::InfoBarItemView() |
39 : insert_index_(0), | 38 : insert_index_(0), |
40 close_button_(NULL), | 39 close_button_(NULL), |
41 icon_(NULL) { | 40 icon_(NULL) { |
42 Init(); | 41 Init(); |
43 } | 42 } |
44 | 43 |
45 InfoBarItemView::~InfoBarItemView() { | 44 InfoBarItemView::~InfoBarItemView() { |
46 } | 45 } |
47 | 46 |
48 // static | 47 // static |
49 int InfoBarItemView::CenterPosition(int size, int target_size) { | 48 int InfoBarItemView::CenterPosition(int size, int target_size) { |
50 return (target_size - size) / 2; | 49 return (target_size - size) / 2; |
51 } | 50 } |
52 | 51 |
53 void InfoBarItemView::GetPreferredSize(CSize* out) { | 52 gfx::Size InfoBarItemView::GetPreferredSize() { |
54 out->cx = GetParent()->width(); | 53 return gfx::Size( |
55 out->cy = static_cast<int>(kInfoBarHeight * animation_->GetCurrentValue()); | 54 GetParent()->width(), |
| 55 static_cast<int>(kInfoBarHeight * animation_->GetCurrentValue())); |
56 } | 56 } |
57 | 57 |
58 // The following is an overall note on the underlying implementation. You don't | 58 // The following is an overall note on the underlying implementation. You don't |
59 // need this in order to use this view. Ignore unless you're editing | 59 // need this in order to use this view. Ignore unless you're editing |
60 // implementation: | 60 // implementation: |
61 // Layout() lays out all of its child views, but it uses insert_index_ to | 61 // Layout() lays out all of its child views, but it uses insert_index_ to |
62 // decide whether to lay out on the left or right. Whenever a view is added or | 62 // decide whether to lay out on the left or right. Whenever a view is added or |
63 // removed the insert_index_ is updated accordingly to make sure it is directly | 63 // removed the insert_index_ is updated accordingly to make sure it is directly |
64 // between left aligned views and right aligned views. Whenever a view is added, | 64 // between left aligned views and right aligned views. Whenever a view is added, |
65 // a spacer view provides padding to the right of the view if the view is | 65 // a spacer view provides padding to the right of the view if the view is |
(...skipping 26 matching lines...) Expand all Loading... |
92 void InfoBarItemView::Layout() { | 92 void InfoBarItemView::Layout() { |
93 int next_x = width() - kButtonHEdgeMargin; | 93 int next_x = width() - kButtonHEdgeMargin; |
94 int height_diff = static_cast<int>(kInfoBarHeight) - height(); | 94 int height_diff = static_cast<int>(kInfoBarHeight) - height(); |
95 const int child_count = GetChildViewCount(); | 95 const int child_count = GetChildViewCount(); |
96 // Anything greater than or equal to insert_index_ is laid out on the right, | 96 // Anything greater than or equal to insert_index_ is laid out on the right, |
97 // with the greatest index (the first one added to the right) being laid out | 97 // with the greatest index (the first one added to the right) being laid out |
98 // rightmost. | 98 // rightmost. |
99 for (int i = child_count - 1; i >= insert_index_ ; i--) { | 99 for (int i = child_count - 1; i >= insert_index_ ; i--) { |
100 View* v = GetChildViewAt(i); | 100 View* v = GetChildViewAt(i); |
101 if (v->IsVisible()) { | 101 if (v->IsVisible()) { |
102 CSize view_size; | 102 gfx::Size view_size = v->GetPreferredSize(); |
103 v->GetPreferredSize(&view_size); | 103 next_x = next_x - view_size.width(); |
104 next_x = next_x - view_size.cx; | |
105 v->SetBounds(next_x, | 104 v->SetBounds(next_x, |
106 CenterPosition(view_size.cy, | 105 CenterPosition(view_size.height(), |
107 static_cast<int>(kInfoBarHeight)) - height_diff, | 106 static_cast<int>(kInfoBarHeight)) - height_diff, |
108 view_size.cx, | 107 view_size.width(), |
109 view_size.cy); | 108 view_size.height()); |
110 } | 109 } |
111 } | 110 } |
112 int left_most_x = next_x; | 111 int left_most_x = next_x; |
113 | 112 |
114 next_x = kInfoBarLeftMargin; | 113 next_x = kInfoBarLeftMargin; |
115 | 114 |
116 // Anything less than insert_index_ is laid out on the left, with the | 115 // Anything less than insert_index_ is laid out on the left, with the |
117 // smallest index (the first one added to the left) being laid out leftmost. | 116 // smallest index (the first one added to the left) being laid out leftmost. |
118 for (int i = 0; i < insert_index_ ; i++) { | 117 for (int i = 0; i < insert_index_ ; i++) { |
119 View* v = GetChildViewAt(i); | 118 View* v = GetChildViewAt(i); |
120 if (v->IsVisible()) { | 119 if (v->IsVisible()) { |
121 CSize view_size; | 120 gfx::Size view_size = v->GetPreferredSize(); |
122 v->GetPreferredSize(&view_size); | |
123 int remaining_space = std::max(0, left_most_x - next_x); | 121 int remaining_space = std::max(0, left_most_x - next_x); |
124 if (view_size.cx > remaining_space) { | 122 if (view_size.width() > remaining_space) { |
125 view_size.cx = remaining_space; | 123 view_size.set_width(remaining_space); |
126 } | 124 } |
127 v->SetBounds(next_x, | 125 v->SetBounds(next_x, |
128 CenterPosition(view_size.cy, | 126 CenterPosition(view_size.height(), |
129 static_cast<int>(kInfoBarHeight)) - height_diff, | 127 static_cast<int>(kInfoBarHeight)) - height_diff, |
130 view_size.cx, | 128 view_size.width(), |
131 view_size.cy); | 129 view_size.height()); |
132 next_x = next_x + view_size.cx; | 130 next_x = next_x + view_size.width(); |
133 } | 131 } |
134 } | 132 } |
135 } | 133 } |
136 | 134 |
137 void InfoBarItemView::DidChangeBounds(const CRect& previous, | 135 void InfoBarItemView::DidChangeBounds(const CRect& previous, |
138 const CRect& current) { | 136 const CRect& current) { |
139 if (GetParent() != NULL) | 137 if (GetParent() != NULL) |
140 Layout(); | 138 Layout(); |
141 } | 139 } |
142 | 140 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); | 280 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); |
283 close_button_->SetListener(this, 0); | 281 close_button_->SetListener(this, 0); |
284 close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE)); | 282 close_button_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_CLOSE)); |
285 AddChildViewTrailing(close_button_); | 283 AddChildViewTrailing(close_button_); |
286 | 284 |
287 animation_.reset(new SlideAnimation(this)); | 285 animation_.reset(new SlideAnimation(this)); |
288 animation_->SetTweenType(SlideAnimation::NONE); | 286 animation_->SetTweenType(SlideAnimation::NONE); |
289 animation_->Show(); | 287 animation_->Show(); |
290 } | 288 } |
291 | 289 |
OLD | NEW |