Commit 1682b254 authored by tfarina@chromium.org's avatar tfarina@chromium.org

Reland "bookmarks: Convert "Remove" link into a LabelButton."

It was reverted in r207804, because it broke some Bookmark tests in interactive_ui_tests.

BUG=231694
TEST=ctrl+D or press the star button in the omnibox, observe the Bookmark Bubble,
there should be a "Remove" Button in the left side of "Edit.." button.
TBR=msw@chromium.org,sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/17074010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@208092 0039d316-1c4b-4281-b951-d872f2087c98
parent 0408c755
......@@ -183,18 +183,18 @@
<message name="IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK" desc="Title of the bubble when re-clicking on a bookmark">
Bookmark
</message>
<message name="IDS_BOOKMARK_BUBBLE_OPTIONS" desc="Title of the link the user can click to edit details of the bookmark">
Edit...
</message>
<message name="IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK" desc="Link for removing the bookmark">
Remove
</message>
<message name="IDS_BOOKMARK_BUBBLE_TITLE_TEXT" desc="Text preceding the title of the page that was bookmarked">
Name:
</message>
<message name="IDS_BOOKMARK_BUBBLE_FOLDER_TEXT" desc="Text preceding the folder selector">
Folder:
</message>
<message name="IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK" desc="Title of the button for removing the bookmark">
Remove
</message>
<message name="IDS_BOOKMARK_BUBBLE_OPTIONS" desc="Title of the button the user can click to edit details of the bookmark">
Edit...
</message>
<if expr="not pp_ifdef('use_titlecase')">
<message name="IDS_BOOKMARK_BUBBLE_CHOOSER_ANOTHER_FOLDER" desc="Text in the combobox allowing the user to choose another folder (by bringing up th editor).">
Choose another folder...
......
......@@ -22,6 +22,7 @@
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/views/bubble/bubble_frame_view.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/combobox/combobox.h"
#include "ui/views/controls/label.h"
......@@ -37,14 +38,8 @@ using views::GridLayout;
namespace {
// Padding between "Title:" and the actual title.
const int kTitlePadding = 4;
// Minimum width for the fields - they will push out the size of the bubble if
// necessary. This should be big enough so that the field pushes the right side
// of the bubble far enough so that the edit button's left edge is to the right
// of the field's left edge.
const int kMinimumFieldSize = 180;
// Minimum width of the the bubble.
const int kMinBubbleWidth = 350;
} // namespace
......@@ -89,6 +84,7 @@ void BookmarkBubbleView::ShowBubble(views::View* anchor_view,
views::BubbleDelegateView::CreateBubble(bookmark_bubble_)->Show();
// Select the entire title textfield contents when the bubble is first shown.
bookmark_bubble_->title_tf_->SelectAll(true);
bookmark_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE);
if (bookmark_bubble_->observer_)
bookmark_bubble_->observer_->OnBookmarkBubbleShown(url);
......@@ -146,9 +142,16 @@ bool BookmarkBubbleView::AcceleratorPressed(
}
void BookmarkBubbleView::Init() {
remove_link_ = new views::Link(l10n_util::GetStringUTF16(
views::Label* title_label = new views::Label(
l10n_util::GetStringUTF16(
newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED :
IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
remove_button_ = new views::LabelButton(this, l10n_util::GetStringUTF16(
IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK));
remove_link_->set_listener(this);
remove_button_->SetStyle(views::Button::STYLE_NATIVE_TEXTBUTTON);
edit_button_ = new views::LabelButton(
this, l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_OPTIONS));
......@@ -166,66 +169,54 @@ void BookmarkBubbleView::Init() {
parent_combobox_->set_listener(this);
parent_combobox_->SetAccessibleName(combobox_label->text());
views::Label* title_label = new views::Label(
l10n_util::GetStringUTF16(
newly_bookmarked_ ? IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARKED :
IDS_BOOKMARK_BUBBLE_PAGE_BOOKMARK));
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
title_label->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
GridLayout* layout = new GridLayout(this);
SetLayoutManager(layout);
ColumnSet* cs = layout->AddColumnSet(0);
// Top (title) row.
cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
0, 0);
cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
const int kTitleColumnSetID = 0;
ColumnSet* cs = layout->AddColumnSet(kTitleColumnSetID);
cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, GridLayout::USE_PREF,
0, 0);
// Middle (input field) rows.
cs = layout->AddColumnSet(2);
// The column layout used for middle and bottom rows.
const int kFirstColumnSetID = 1;
cs = layout->AddColumnSet(kFirstColumnSetID);
cs->AddColumn(GridLayout::LEADING, GridLayout::CENTER, 0,
GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(0, views::kRelatedControlHorizontalSpacing);
cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
GridLayout::USE_PREF, 0, kMinimumFieldSize);
cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
GridLayout::USE_PREF, 0, 0);
cs->AddPaddingColumn(1, views::kUnrelatedControlLargeHorizontalSpacing);
// Bottom (buttons) row.
cs = layout->AddColumnSet(3);
cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
GridLayout::USE_PREF, 0, 0);
// We subtract 2 to account for the natural button padding, and
// to bring the separation visually in line with the row separation
// height.
cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing - 2);
cs->AddPaddingColumn(0, views::kRelatedButtonHSpacing);
cs->AddColumn(GridLayout::LEADING, GridLayout::TRAILING, 0,
GridLayout::USE_PREF, 0, 0);
layout->StartRow(0, 0);
layout->StartRow(0, kTitleColumnSetID);
layout->AddView(title_label);
layout->AddView(remove_link_);
layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
layout->StartRow(0, 2);
layout->StartRow(0, kFirstColumnSetID);
views::Label* label = new views::Label(
l10n_util::GetStringUTF16(IDS_BOOKMARK_BUBBLE_TITLE_TEXT));
layout->AddView(label);
title_tf_ = new views::Textfield();
title_tf_->SetText(GetTitle());
layout->AddView(title_tf_);
layout->AddView(title_tf_, 5, 1);
layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
layout->AddPaddingRow(0, views::kUnrelatedControlHorizontalSpacing);
layout->StartRow(0, 2);
layout->StartRow(0, kFirstColumnSetID);
layout->AddView(combobox_label);
layout->AddView(parent_combobox_);
layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
layout->AddView(parent_combobox_, 5, 1);
layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
layout->StartRow(0, 3);
layout->StartRow(0, kFirstColumnSetID);
layout->SkipColumns(2);
layout->AddView(remove_button_);
layout->AddView(edit_button_);
layout->AddView(close_button_);
......@@ -246,15 +237,20 @@ BookmarkBubbleView::BookmarkBubbleView(views::View* anchor_view,
BookmarkModelFactory::GetForProfile(profile_),
BookmarkModelFactory::GetForProfile(profile_)->
GetMostRecentlyAddedNodeForURL(url)),
remove_link_(NULL),
remove_button_(NULL),
edit_button_(NULL),
close_button_(NULL),
title_tf_(NULL),
parent_combobox_(NULL),
remove_bookmark_(false),
apply_edits_(true) {
const SkColor background_color = GetNativeTheme()->GetSystemColor(
ui::NativeTheme::kColorId_DialogBackground);
set_color(background_color);
set_background(views::Background::CreateSolidBackground(background_color));
set_margins(gfx::Insets(12, 19, 18, 18));
// Compensate for built-in vertical padding in the anchor view's image.
set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
set_anchor_view_insets(gfx::Insets(7, 0, 7, 0));
}
string16 BookmarkBubbleView::GetTitle() {
......@@ -269,21 +265,17 @@ string16 BookmarkBubbleView::GetTitle() {
return string16();
}
gfx::Size BookmarkBubbleView::GetMinimumSize() {
gfx::Size size(views::BubbleDelegateView::GetPreferredSize());
size.SetToMax(gfx::Size(kMinBubbleWidth, 0));
return size;
}
void BookmarkBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
HandleButtonPressed(sender);
}
void BookmarkBubbleView::LinkClicked(views::Link* source, int event_flags) {
DCHECK_EQ(remove_link_, source);
content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
// Set this so we remove the bookmark after the window closes.
remove_bookmark_ = true;
apply_edits_ = false;
StartFade(false);
}
void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) {
if (combobox->selected_index() + 1 == parent_model_.GetItemCount()) {
content::RecordAction(UserMetricsAction("BookmarkBubble_EditFromCombobox"));
......@@ -292,7 +284,13 @@ void BookmarkBubbleView::OnSelectedIndexChanged(views::Combobox* combobox) {
}
void BookmarkBubbleView::HandleButtonPressed(views::Button* sender) {
if (sender == edit_button_) {
if (sender == remove_button_) {
content::RecordAction(UserMetricsAction("BookmarkBubble_Unstar"));
// Set this so we remove the bookmark after the window closes.
remove_bookmark_ = true;
apply_edits_ = false;
StartFade(false);
} else if (sender == edit_button_) {
content::RecordAction(UserMetricsAction("BookmarkBubble_Edit"));
ShowEditor();
} else {
......
......@@ -13,7 +13,6 @@
#include "ui/views/bubble/bubble_delegate.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/controls/combobox/combobox_listener.h"
#include "ui/views/controls/link_listener.h"
class BookmarkBubbleViewObserver;
class Profile;
......@@ -28,7 +27,6 @@ class Textfield;
// bookmark it is created with. Don't create a BookmarkBubbleView directly,
// instead use the static Show method.
class BookmarkBubbleView : public views::BubbleDelegateView,
public views::LinkListener,
public views::ButtonListener,
public views::ComboboxListener {
public:
......@@ -68,10 +66,8 @@ class BookmarkBubbleView : public views::BubbleDelegateView,
// Returns the title to display.
string16 GetTitle();
// Overridden from views::LinkListener:
// Either unstars the item or shows the bookmark editor (depending upon which
// link was clicked).
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
// Overridden from views::View:
virtual gfx::Size GetMinimumSize() OVERRIDE;
// Overridden from views::ButtonListener:
// Closes the bubble or opens the edit dialog.
......@@ -107,8 +103,8 @@ class BookmarkBubbleView : public views::BubbleDelegateView,
RecentlyUsedFoldersComboModel parent_model_;
// Link for removing/unstarring the bookmark.
views::Link* remove_link_;
// Button for removing the bookmark.
views::LabelButton* remove_button_;
// Button to bring up the editor.
views::LabelButton* edit_button_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment