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 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bubble_view.h" |
6 | 6 |
7 #include "base/string16.h" | 7 #include "base/string16.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 26 matching lines...) Expand all Loading... | |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Padding between "Title:" and the actual title. | 40 // Padding between "Title:" and the actual title. |
41 const int kTitlePadding = 4; | 41 const int kTitlePadding = 4; |
42 | 42 |
43 // Minimum width for the fields - they will push out the size of the bubble if | 43 // Minimum width for the fields - they will push out the size of the bubble if |
44 // necessary. This should be big enough so that the field pushes the right side | 44 // necessary. This should be big enough so that the field pushes the right side |
45 // of the bubble far enough so that the edit button's left edge is to the right | 45 // of the bubble far enough so that the edit button's left edge is to the right |
46 // of the field's left edge. | 46 // of the field's left edge. |
47 const int kMinimumFieldSize = 180; | 47 const int kMinimumFieldSize = 180; |
msw
2013/06/01 01:18:48
Make this kMinBubbleWidth = 336 (maybe 340) to mat
tfarina
2013/06/01 03:33:42
Done.
| |
48 | 48 |
49 } // namespace | 49 } // namespace |
50 | 50 |
51 // Declared in browser_dialogs.h so callers don't have to depend on our header. | 51 // Declared in browser_dialogs.h so callers don't have to depend on our header. |
52 | 52 |
53 namespace chrome { | 53 namespace chrome { |
54 | 54 |
55 void ShowBookmarkBubbleView(views::View* anchor_view, | 55 void ShowBookmarkBubbleView(views::View* anchor_view, |
56 BookmarkBubbleViewObserver* observer, | 56 BookmarkBubbleViewObserver* observer, |
57 Profile* profile, | 57 Profile* profile, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 | 121 |
122 void BookmarkBubbleView::WindowClosing() { | 122 void BookmarkBubbleView::WindowClosing() { |
123 // We have to reset |bubble_| here, not in our destructor, because we'll be | 123 // We have to reset |bubble_| here, not in our destructor, because we'll be |
124 // destroyed asynchronously and the shown state will be checked before then. | 124 // destroyed asynchronously and the shown state will be checked before then. |
125 DCHECK_EQ(bookmark_bubble_, this); | 125 DCHECK_EQ(bookmark_bubble_, this); |
126 bookmark_bubble_ = NULL; | 126 bookmark_bubble_ = NULL; |
127 | 127 |
128 if (observer_) | 128 if (observer_) |
129 observer_->OnBookmarkBubbleHidden(); | 129 observer_->OnBookmarkBubbleHidden(); |
130 } | 130 } |
131 | 131 |
msw
2013/06/01 01:18:48
Override GetPreferredSize() or GetMinimumSize to r
| |
132 bool BookmarkBubbleView::AcceleratorPressed( | 132 bool BookmarkBubbleView::AcceleratorPressed( |
133 const ui::Accelerator& accelerator) { | 133 const ui::Accelerator& accelerator) { |
134 if (accelerator.key_code() == ui::VKEY_RETURN) { | 134 if (accelerator.key_code() == ui::VKEY_RETURN) { |
135 if (edit_button_->HasFocus()) | 135 if (edit_button_->HasFocus()) |
136 HandleButtonPressed(edit_button_); | 136 HandleButtonPressed(edit_button_); |
137 else | 137 else |
138 HandleButtonPressed(close_button_); | 138 HandleButtonPressed(close_button_); |
139 return true; | 139 return true; |
140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { | 140 } else if (accelerator.key_code() == ui::VKEY_ESCAPE) { |
141 remove_bookmark_ = newly_bookmarked_; | 141 remove_bookmark_ = newly_bookmarked_; |
142 apply_edits_ = false; | 142 apply_edits_ = false; |
143 } | 143 } |
144 | 144 |
145 return BubbleDelegateView::AcceleratorPressed(accelerator); | 145 return BubbleDelegateView::AcceleratorPressed(accelerator); |
146 } | 146 } |
147 | 147 |
148 void BookmarkBubbleView::Init() { | 148 void BookmarkBubbleView::Init() { |
149 remove_link_ = new views::Link(l10n_util::GetStringUTF16( | 149 remove_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16( |
150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); | 150 IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK)); |
151 remove_link_->set_listener(this); | 151 remove_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
152 | 152 |
153 edit_button_ = new views::LabelButton( | 153 edit_button_ = new views::LabelButton( |
154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); | 154 this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS)); |
155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 155 edit_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
156 | 156 |
157 close_button_ = new views::LabelButton( | 157 close_button_ = new views::LabelButton( |
158 this, l10n_util::GetStringUTF16(IDS_DONE)); | 158 this, l10n_util::GetStringUTF16(IDS_DONE)); |
159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); | 159 close_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON); |
160 close_button_->SetIsDefault(true); | 160 close_button_->SetIsDefault(true); |
161 | 161 |
162 views::Label* combobox_label = new views::Label( | 162 views::Label* combobox_label = new views::Label( |
163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); | 163 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_FOLDER_TEXT)); |
164 | 164 |
165 parent_combobox_ = new views::Combobox(&parent_model_); | 165 parent_combobox_ = new views::Combobox(&parent_model_); |
166 parent_combobox_->set_listener(this); | 166 parent_combobox_->set_listener(this); |
167 parent_combobox_->SetAccessibleName(combobox_label->text()); | 167 parent_combobox_->SetAccessibleName(combobox_label->text()); |
168 | 168 |
169 views::Label* title_label = new views::Label( | 169 views::Label* title_label = new views::Label( |
msw
2013/06/01 01:07:28
Try GetBubbleFrameView()->SetTitle(...); remove th
tfarina
2013/06/01 03:33:42
Not yet, looking into ViewHierarchyChanged() appro
| |
170 l10n_util::GetStringUTF16( | 170 l10n_util::GetStringUTF16( |
171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : | 171 newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED : |
172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); | 172 IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK)); |
173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 173 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
174 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 174 title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
175 | 175 |
176 GridLayout* layout = new GridLayout(this); | 176 GridLayout* layout = new GridLayout(this); |
177 SetLayoutManager(layout); | 177 SetLayoutManager(layout); |
178 | 178 |
179 ColumnSet* cs = layout->AddColumnSet(0); | 179 ColumnSet* cs = layout->AddColumnSet(0); |
180 | 180 |
181 // Top (title) row. | 181 // Top (title) row. |
182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 182 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
183 0, 0); | 183 0, 0); |
184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 184 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, | 185 cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF, |
186 0, 0); | 186 0, 0); |
187 | 187 |
188 // Middle (input field) rows. | |
189 cs = layout->AddColumnSet(2); | 188 cs = layout->AddColumnSet(2); |
190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 189 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
191 GridLayout::USE_PREF, 0, 0); | 190 GridLayout::USE_PREF, 0, 0); |
192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 191 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
msw
2013/06/01 01:07:28
This value (8) needs to be increased to match 15 i
tfarina
2013/06/01 03:33:42
Done.
| |
193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 192 |
193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0, | |
194 GridLayout::USE_PREF, 0, kMinimumFieldSize); | 194 GridLayout::USE_PREF, 0, kMinimumFieldSize); |
msw
2013/06/01 01:18:48
Remove kMinimumFieldSize here.
tfarina
2013/06/01 03:33:42
Done.
| |
195 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); | |
195 | 196 |
196 // Bottom (buttons) row. | |
197 cs = layout->AddColumnSet(3); | |
198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | |
199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 197 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
200 GridLayout::USE_PREF, 0, 0); | 198 GridLayout::USE_PREF, 0, 0); |
201 // We subtract 2 to account for the natural button padding, and | 199 // We subtract 2 to account for the natural button padding, and |
202 // to bring the separation visually in line with the row separation | 200 // to bring the separation visually in line with the row separation |
203 // height. | 201 // height. |
204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 202 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
203 | |
205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 204 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
206 GridLayout::USE_PREF, 0, 0); | 205 GridLayout::USE_PREF, 0, 0); |
207 | 206 |
208 layout->StartRow(0, 0); | 207 layout->StartRow(0, 0); |
209 layout->AddView(title_label); | 208 layout->AddView(title_label); |
210 layout->AddView(remove_link_); | |
211 | 209 |
212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 210 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
211 | |
213 layout->StartRow(0, 2); | 212 layout->StartRow(0, 2); |
214 views::Label* label = new views::Label( | 213 views::Label* label = new views::Label( |
215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 214 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
216 layout->AddView(label); | 215 layout->AddView(label); |
217 title_tf_ = new views::Textfield(); | 216 title_tf_ = new views::Textfield(); |
218 title_tf_->SetText(GetTitle()); | 217 title_tf_->SetText(GetTitle()); |
219 layout->AddView(title_tf_); | 218 layout->AddView(title_tf_, 5, 1); |
220 | 219 |
221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 220 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
msw
2013/06/01 01:07:28
This value (4) needs to be increased to match 10 i
tfarina
2013/06/01 03:33:42
Done.
| |
222 | 221 |
223 layout->StartRow(0, 2); | 222 layout->StartRow(0, 2); |
224 layout->AddView(combobox_label); | 223 layout->AddView(combobox_label); |
225 layout->AddView(parent_combobox_); | 224 layout->AddView(parent_combobox_, 5, 1); |
225 | |
226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
msw
2013/06/01 01:07:28
ditto, use kRelatedControlVerticalSpacing.
tfarina
2013/06/01 03:33:42
Done.
| |
227 | 227 |
228 layout->StartRow(0, 3); | 228 layout->StartRow(0, 2); |
229 layout->SkipColumns(2); | |
230 layout->AddView(remove_button_); | |
229 layout->AddView(edit_button_); | 231 layout->AddView(edit_button_); |
230 layout->AddView(close_button_); | 232 layout->AddView(close_button_); |
231 | 233 |
232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 234 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
233 } | 235 } |
234 | 236 |
235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, | 237 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, |
msw
2013/06/01 01:07:28
The left/right/bottom insets are 7 and should be 2
tfarina
2013/06/01 03:33:42
Done.
| |
236 BookmarkBubbleViewObserver* observer, | 238 BookmarkBubbleViewObserver* observer, |
237 Profile* profile, | 239 Profile* profile, |
238 const GURL& url, | 240 const GURL& url, |
239 bool newly_bookmarked) | 241 bool newly_bookmarked) |
240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 242 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
241 observer_(observer), | 243 observer_(observer), |
242 profile_(profile), | 244 profile_(profile), |
243 url_(url), | 245 url_(url), |
244 newly_bookmarked_(newly_bookmarked), | 246 newly_bookmarked_(newly_bookmarked), |
245 parent_model_( | 247 parent_model_( |
246 BookmarkModelFactory::GetForProfile(profile_), | 248 BookmarkModelFactory::GetForProfile(profile_), |
247 BookmarkModelFactory::GetForProfile(profile_)-> | 249 BookmarkModelFactory::GetForProfile(profile_)-> |
248 GetMostRecentlyAddedNodeForURL(url)), | 250 GetMostRecentlyAddedNodeForURL(url)), |
249 remove_link_(NULL), | 251 remove_button_(NULL), |
250 edit_button_(NULL), | 252 edit_button_(NULL), |
251 close_button_(NULL), | 253 close_button_(NULL), |
252 title_tf_(NULL), | 254 title_tf_(NULL), |
253 parent_combobox_(NULL), | 255 parent_combobox_(NULL), |
254 remove_bookmark_(false), | 256 remove_bookmark_(false), |
255 apply_edits_(true) { | 257 apply_edits_(true) { |
256 // Compensate for built-in vertical padding in the anchor view's image. | 258 // Compensate for built-in vertical padding in the anchor view's image. |
257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 259 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
258 } | 260 } |
259 | 261 |
260 string16 BookmarkBubbleView::GetTitle() { | 262 string16 BookmarkBubbleView::GetTitle() { |
261 BookmarkModel* bookmark_model = | 263 BookmarkModel* bookmark_model = |
262 BookmarkModelFactory::GetForProfile(profile_); | 264 BookmarkModelFactory::GetForProfile(profile_); |
263 const BookmarkNode* node = | 265 const BookmarkNode* node = |
264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 266 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
265 if (node) | 267 if (node) |
266 return node->GetTitle(); | 268 return node->GetTitle(); |
267 else | 269 else |
268 NOTREACHED(); | 270 NOTREACHED(); |
269 return string16(); | 271 return string16(); |
270 } | 272 } |
271 | 273 |
272 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 274 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
273 const ui::Event& event) { | 275 const ui::Event& event) { |
274 HandleButtonPressed(sender); | 276 HandleButtonPressed(sender); |
275 } | 277 } |
276 | 278 |
277 void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) { | |
278 DCHECK_EQ(remove_link_, source); | |
279 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
280 | |
281 // Set this so we remove the bookmark after the window closes. | |
282 remove_bookmark_ = true; | |
283 apply_edits_ = false; | |
284 StartFade(false); | |
285 } | |
286 | |
287 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { | 279 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { |
288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 280 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 281 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
290 ShowEditor(); | 282 ShowEditor(); |
291 } | 283 } |
292 } | 284 } |
293 | 285 |
294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 286 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
295 if (sender == edit_button_) { | 287 if (sender == remove_button_) { |
288 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
289 // Set this so we remove the bookmark after the window closes. | |
290 remove_bookmark_ = true; | |
291 apply_edits_ = false; | |
292 StartFade(false); | |
293 } else if (sender == edit_button_) { | |
296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 294 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
297 ShowEditor(); | 295 ShowEditor(); |
298 } else { | 296 } else { |
299 DCHECK_EQ(close_button_, sender); | 297 DCHECK_EQ(close_button_, sender); |
300 StartFade(false); | 298 StartFade(false); |
301 } | 299 } |
302 } | 300 } |
303 | 301 |
304 void BookmarkBubbleView::ShowEditor() { | 302 void BookmarkBubbleView::ShowEditor() { |
305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 303 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
(...skipping 20 matching lines...) Expand all Loading... | |
326 if (node) { | 324 if (node) { |
327 const string16 new_title = title_tf_->text(); | 325 const string16 new_title = title_tf_->text(); |
328 if (new_title != node->GetTitle()) { | 326 if (new_title != node->GetTitle()) { |
329 model->SetTitle(node, new_title); | 327 model->SetTitle(node, new_title); |
330 content::RecordAction( | 328 content::RecordAction( |
331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 329 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
332 } | 330 } |
333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 331 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
334 } | 332 } |
335 } | 333 } |
OLD | NEW |