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 <string> | 5 #include <string> |
6 | 6 |
7 #include "chrome/views/decision.h" | 7 #include "chrome/views/decision.h" |
8 | 8 |
9 #include "chrome/common/resource_bundle.h" | 9 #include "chrome/common/resource_bundle.h" |
10 #include "chrome/views/label.h" | 10 #include "chrome/views/label.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 | 73 |
74 void Decision::Layout() { | 74 void Decision::Layout() { |
75 CRect lb; | 75 CRect lb; |
76 GetLocalBounds(&lb, false); | 76 GetLocalBounds(&lb, false); |
77 | 77 |
78 // Resize for padding. | 78 // Resize for padding. |
79 lb.DeflateRect(kPaddingEdge, kPaddingEdge); | 79 lb.DeflateRect(kPaddingEdge, kPaddingEdge); |
80 int width = lb.Width(); | 80 int width = lb.Width(); |
81 | 81 |
82 CPoint position(lb.TopLeft()); | 82 CPoint position(lb.TopLeft()); |
83 CSize size; | 83 gfx::Size size = title_label_->GetPreferredSize(); |
84 title_label_->GetPreferredSize(&size); | 84 title_label_->SetBounds(position.x, position.y, width, size.height()); |
85 title_label_->SetBounds(position.x, position.y, width, size.cy); | 85 position.y += size.height() + kSpacingInfoBottom; |
86 position.y += size.cy + kSpacingInfoBottom; | |
87 | 86 |
88 size.cy = details_label_->GetHeightForWidth(width); | 87 size.set_height(details_label_->GetHeightForWidth(width)); |
89 details_label_->SetBounds(position.x, position.y, width, size.cy); | 88 details_label_->SetBounds(position.x, position.y, width, size.height()); |
90 position.y += size.cy + kSpacingInfoBottom; | 89 position.y += size.height() + kSpacingInfoBottom; |
91 | 90 |
92 for (std::vector<Option*>::const_iterator iter = options_.begin(); | 91 for (std::vector<Option*>::const_iterator iter = options_.begin(); |
93 iter != options_.end(); ++iter) { | 92 iter != options_.end(); ++iter) { |
94 Option* option = *iter; | 93 Option* option = *iter; |
95 option->GetPreferredSize(&size); | 94 size = option->GetPreferredSize(); |
96 option->SetBounds(position.x, position.y, width, size.cy); | 95 option->SetBounds(position.x, position.y, width, size.height()); |
97 option->Layout(); | 96 option->Layout(); |
98 position.y += size.cy + kSpacingInfoBottom; | 97 position.y += size.height() + kSpacingInfoBottom; |
99 } | 98 } |
100 } | 99 } |
101 | 100 |
102 void Decision::GetPreferredSize(CSize *out) { | 101 gfx::Size Decision::GetPreferredSize() { |
103 int width = 0; | 102 int width = 0; |
104 int height = 0; | 103 int height = 0; |
105 | 104 |
106 // We need to find the largest width from the title and the options, as the | 105 // We need to find the largest width from the title and the options, as the |
107 // details label is multi-line and we need to known its width in order to | 106 // details label is multi-line and we need to known its width in order to |
108 // compute its height. | 107 // compute its height. |
109 CSize size; | 108 gfx::Size size = title_label_->GetPreferredSize(); |
110 title_label_->GetPreferredSize(&size); | 109 width = size.width(); |
111 width = size.cx; | 110 height = size.height() + kSpacingInfoBottom; |
112 height = size.cy + kSpacingInfoBottom; | |
113 | 111 |
114 for (std::vector<Option*>::const_iterator iter = options_.begin(); | 112 for (std::vector<Option*>::const_iterator iter = options_.begin(); |
115 iter != options_.end(); ++iter) { | 113 iter != options_.end(); ++iter) { |
116 (*iter)->GetPreferredSize(&size); | 114 size = (*iter)->GetPreferredSize(); |
117 if (size.cx > width) | 115 if (size.width() > width) |
118 width = size.cx; | 116 width = size.width(); |
119 height += size.cy + kSpacingInfoBottom; | 117 height += size.height() + kSpacingInfoBottom; |
120 } | 118 } |
121 | 119 |
122 // Now we can compute the details label height. | 120 // Now we can compute the details label height. |
123 height += details_label_->GetHeightForWidth(width) + kSpacingInfoBottom; | 121 height += details_label_->GetHeightForWidth(width) + kSpacingInfoBottom; |
124 | 122 |
125 out->cx = width + 2 * kPaddingEdge; | 123 return gfx::Size(width + 2 * kPaddingEdge, height + 2 * kPaddingEdge); |
126 out->cy = height + 2 * kPaddingEdge; | |
127 } | 124 } |
128 | 125 |
129 Option::Option(int command_id, | 126 Option::Option(int command_id, |
130 const std::wstring& description, | 127 const std::wstring& description, |
131 const std::wstring& action, | 128 const std::wstring& action, |
132 Controller* controller) | 129 Controller* controller) |
133 : command_id_(command_id), | 130 : command_id_(command_id), |
134 controller_(controller) { | 131 controller_(controller) { |
135 | 132 |
136 GridLayout* layout = new GridLayout(this); | 133 GridLayout* layout = new GridLayout(this); |
(...skipping 16 matching lines...) Expand all Loading... |
153 button->SetListener(this); | 150 button->SetListener(this); |
154 layout->AddView(button); | 151 layout->AddView(button); |
155 } | 152 } |
156 | 153 |
157 void Option::ButtonPressed(ChromeViews::NativeButton* sender) { | 154 void Option::ButtonPressed(ChromeViews::NativeButton* sender) { |
158 controller_->ExecuteCommand(command_id_); | 155 controller_->ExecuteCommand(command_id_); |
159 } | 156 } |
160 | 157 |
161 } // namespace ChromeViews | 158 } // namespace ChromeViews |
162 | 159 |
OLD | NEW |