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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
(...skipping 24 matching lines...) Expand all Loading... | |
186 0, 0); | 186 0, 0); |
187 | 187 |
188 // Middle (input field) rows. | 188 // Middle (input field) rows. |
189 cs = layout->AddColumnSet(2); | 189 cs = layout->AddColumnSet(2); |
190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, | 190 cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0, |
191 GridLayout::USE_PREF, 0, 0); | 191 GridLayout::USE_PREF, 0, 0); |
192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); | 192 cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing); |
193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 193 cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
194 GridLayout::USE_PREF, 0, kMinimumFieldSize); | 194 GridLayout::USE_PREF, 0, kMinimumFieldSize); |
195 | 195 |
196 // Bottom (buttons) row. | 196 // Bottom (buttons) row. |
msw
2013/05/31 23:13:48
Try a different approach: Remove ColumnSet(2) (use
| |
197 cs = layout->AddColumnSet(3); | 197 cs = layout->AddColumnSet(3); |
198 cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing); | 198 cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing); |
199 cs->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | |
200 GridLayout::USE_PREF, 0, 0); | |
201 cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | |
199 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 202 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
200 GridLayout::USE_PREF, 0, 0); | 203 GridLayout::USE_PREF, 0, 0); |
201 // We subtract 2 to account for the natural button padding, and | 204 // We subtract 2 to account for the natural button padding, and |
202 // to bring the separation visually in line with the row separation | 205 // to bring the separation visually in line with the row separation |
203 // height. | 206 // height. |
204 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); | 207 cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2); |
205 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, | 208 cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0, |
206 GridLayout::USE_PREF, 0, 0); | 209 GridLayout::USE_PREF, 0, 0); |
207 | 210 |
208 layout->StartRow(0, 0); | 211 layout->StartRow(0, 0); |
209 layout->AddView(title_label); | 212 layout->AddView(title_label); |
210 layout->AddView(remove_link_); | |
211 | 213 |
212 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 214 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
213 layout->StartRow(0, 2); | 215 layout->StartRow(0, 2); |
214 views::Label* label = new views::Label( | 216 views::Label* label = new views::Label( |
215 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); | 217 l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT)); |
216 layout->AddView(label); | 218 layout->AddView(label); |
217 title_tf_ = new views::Textfield(); | 219 title_tf_ = new views::Textfield(); |
218 title_tf_->SetText(GetTitle()); | 220 title_tf_->SetText(GetTitle()); |
219 layout->AddView(title_tf_); | 221 layout->AddView(title_tf_); |
220 | 222 |
221 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 223 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
222 | 224 |
223 layout->StartRow(0, 2); | 225 layout->StartRow(0, 2); |
224 layout->AddView(combobox_label); | 226 layout->AddView(combobox_label); |
225 layout->AddView(parent_combobox_); | 227 layout->AddView(parent_combobox_); |
226 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 228 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
227 | 229 |
228 layout->StartRow(0, 3); | 230 layout->StartRow(0, 3); |
231 layout->AddView(remove_button_); | |
229 layout->AddView(edit_button_); | 232 layout->AddView(edit_button_); |
230 layout->AddView(close_button_); | 233 layout->AddView(close_button_); |
231 | 234 |
232 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); | 235 AddAccelerator(ui::Accelerator(ui::VKEY_RETURN, ui::EF_NONE)); |
233 } | 236 } |
234 | 237 |
235 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, | 238 BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view, |
236 BookmarkBubbleViewObserver* observer, | 239 BookmarkBubbleViewObserver* observer, |
237 Profile* profile, | 240 Profile* profile, |
238 const GURL& url, | 241 const GURL& url, |
239 bool newly_bookmarked) | 242 bool newly_bookmarked) |
240 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | 243 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
241 observer_(observer), | 244 observer_(observer), |
242 profile_(profile), | 245 profile_(profile), |
243 url_(url), | 246 url_(url), |
244 newly_bookmarked_(newly_bookmarked), | 247 newly_bookmarked_(newly_bookmarked), |
245 parent_model_( | 248 parent_model_( |
246 BookmarkModelFactory::GetForProfile(profile_), | 249 BookmarkModelFactory::GetForProfile(profile_), |
247 BookmarkModelFactory::GetForProfile(profile_)-> | 250 BookmarkModelFactory::GetForProfile(profile_)-> |
248 GetMostRecentlyAddedNodeForURL(url)), | 251 GetMostRecentlyAddedNodeForURL(url)), |
249 remove_link_(NULL), | 252 remove_button_(NULL), |
250 edit_button_(NULL), | 253 edit_button_(NULL), |
251 close_button_(NULL), | 254 close_button_(NULL), |
252 title_tf_(NULL), | 255 title_tf_(NULL), |
253 parent_combobox_(NULL), | 256 parent_combobox_(NULL), |
254 remove_bookmark_(false), | 257 remove_bookmark_(false), |
255 apply_edits_(true) { | 258 apply_edits_(true) { |
256 // Compensate for built-in vertical padding in the anchor view's image. | 259 // Compensate for built-in vertical padding in the anchor view's image. |
257 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 260 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
258 } | 261 } |
259 | 262 |
260 string16 BookmarkBubbleView::GetTitle() { | 263 string16 BookmarkBubbleView::GetTitle() { |
261 BookmarkModel* bookmark_model = | 264 BookmarkModel* bookmark_model = |
262 BookmarkModelFactory::GetForProfile(profile_); | 265 BookmarkModelFactory::GetForProfile(profile_); |
263 const BookmarkNode* node = | 266 const BookmarkNode* node = |
264 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); | 267 bookmark_model->GetMostRecentlyAddedNodeForURL(url_); |
265 if (node) | 268 if (node) |
266 return node->GetTitle(); | 269 return node->GetTitle(); |
267 else | 270 else |
268 NOTREACHED(); | 271 NOTREACHED(); |
269 return string16(); | 272 return string16(); |
270 } | 273 } |
271 | 274 |
272 void BookmarkBubbleView::ButtonPressed(views::Button* sender, | 275 void BookmarkBubbleView::ButtonPressed(views::Button* sender, |
273 const ui::Event& event) { | 276 const ui::Event& event) { |
274 HandleButtonPressed(sender); | 277 HandleButtonPressed(sender); |
275 } | 278 } |
276 | 279 |
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) { | 280 void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) { |
288 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { | 281 if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) { |
289 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); | 282 content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox")); |
290 ShowEditor(); | 283 ShowEditor(); |
291 } | 284 } |
292 } | 285 } |
293 | 286 |
294 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { | 287 void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) { |
295 if (sender == edit_button_) { | 288 if (sender == remove_button_) { |
289 content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar")); | |
290 // Set this so we remove the bookmark after the window closes. | |
291 remove_bookmark_ = true; | |
292 apply_edits_ = false; | |
293 StartFade(false); | |
294 } else if (sender == edit_button_) { | |
296 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); | 295 content::RecordAction(UserMetricsAction("BookmarkBubble_Edit")); |
297 ShowEditor(); | 296 ShowEditor(); |
298 } else { | 297 } else { |
299 DCHECK_EQ(close_button_, sender); | 298 DCHECK_EQ(close_button_, sender); |
300 StartFade(false); | 299 StartFade(false); |
301 } | 300 } |
302 } | 301 } |
303 | 302 |
304 void BookmarkBubbleView::ShowEditor() { | 303 void BookmarkBubbleView::ShowEditor() { |
305 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( | 304 const BookmarkNode* node = BookmarkModelFactory::GetForProfile( |
(...skipping 20 matching lines...) Expand all Loading... | |
326 if (node) { | 325 if (node) { |
327 const string16 new_title = title_tf_->text(); | 326 const string16 new_title = title_tf_->text(); |
328 if (new_title != node->GetTitle()) { | 327 if (new_title != node->GetTitle()) { |
329 model->SetTitle(node, new_title); | 328 model->SetTitle(node, new_title); |
330 content::RecordAction( | 329 content::RecordAction( |
331 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); | 330 UserMetricsAction("BookmarkBubble_ChangeTitleInBubble")); |
332 } | 331 } |
333 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); | 332 parent_model_.MaybeChangeParent(node, parent_combobox_->selected_index()); |
334 } | 333 } |
335 } | 334 } |
OLD | NEW |