Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5969)

Unified Diff: chrome/browser/ui/views/password_generation_bubble_view.cc

Issue 10919111: Update Windows UI for the Password Generation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix a build problem. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/password_generation_bubble_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/password_generation_bubble_view.cc
diff --git a/chrome/browser/ui/views/password_generation_bubble_view.cc b/chrome/browser/ui/views/password_generation_bubble_view.cc
index 80873f8e4b55a8f68efe96a8873ca98d8ddac961..fb54789fee1ab7fbf11de77475a4d5025bf76fb8 100644
--- a/chrome/browser/ui/views/password_generation_bubble_view.cc
+++ b/chrome/browser/ui/views/password_generation_bubble_view.cc
@@ -15,81 +15,199 @@
#include "content/public/browser/render_view_host.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "third_party/skia/include/core/SkPaint.h"
#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/theme_provider.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/border.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/layout/grid_layout.h"
#include "ui/views/layout/layout_constants.h"
-using views::ColumnSet;
-using views::GridLayout;
+namespace {
+// Constants for PasswordGenerationBubbleView.
+const int kBubbleMargin = 9;
+const int kButtonHorizontalSpacing = 4;
+const int kButtonWidth = 65;
+const int kDefaultTextFieldChars = 18;
+const int kTitleLabelVerticalOffset = -3;
+const int kVerticalPadding = 8;
+
+// Constants for Text fieldWrapper.
+const int kTextfieldHorizontalPadding = 2;
+const int kTextfieldVerticalPadding = 3;
+const int kWrapperBorderSize = 1;
+
+// This class handles layout so that it looks like a Textfield and ImageButton
+// are part of one logical textfield with the button on the right side of the
+// field. It also assumes that the textfield is already sized appropriately
+// and will alter the image size to fit.
+class TextfieldWrapper : public views::View {
+ public:
+ TextfieldWrapper(views::Textfield* textfield,
+ views::ImageButton* image_button);
+ virtual ~TextfieldWrapper();
+
+ virtual void Layout() OVERRIDE;
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+
+ private:
+ gfx::Size GetImageSize() const;
+
+ views::Textfield* textfield_;
+ views::ImageButton* image_button_;
+};
+
+TextfieldWrapper::TextfieldWrapper(views::Textfield* textfield,
+ views::ImageButton* image_button)
+ : textfield_(textfield),
+ image_button_(image_button) {
+ textfield_->RemoveBorder();
+ set_border(views::Border::CreateSolidBorder(kWrapperBorderSize,
+ SK_ColorGRAY));
+
+ AddChildView(textfield_);
+ AddChildView(image_button);
+}
+
+TextfieldWrapper::~TextfieldWrapper() {}
+
+void TextfieldWrapper::Layout() {
+ // Add some spacing between the textfield and the border.
+ textfield_->SetPosition(gfx::Point(kTextfieldHorizontalPadding,
+ kTextfieldVerticalPadding));
+ textfield_->SizeToPreferredSize();
+
+ // Button should be offset one pixel from the end of the textfield so that
+ // there is no overlap. It is also displaced down by the size of the border
+ // so it doesn't overlap with it either.
+ int button_x = (textfield_->GetPreferredSize().width() +
+ kTextfieldHorizontalPadding + 1);
+ image_button_->SetPosition(gfx::Point(button_x,
+ kWrapperBorderSize));
+
+ // Make sure that the image is centered after cropping.
+ image_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
+ views::ImageButton::ALIGN_MIDDLE);
+
+ image_button_->SetSize(GetImageSize());
+}
+
+gfx::Size TextfieldWrapper::GetPreferredSize() {
+ int width = (textfield_->GetPreferredSize().width() +
+ GetImageSize().width() +
+ kTextfieldHorizontalPadding * 3);
+ int height = (textfield_->GetPreferredSize().height() +
+ kTextfieldVerticalPadding * 2);
+
+ return gfx::Size(width, height);
+}
+
+gfx::Size TextfieldWrapper::GetImageSize() const {
+ // The image is sized so that it fills the space between the borders
+ // completely.
+ int size = (textfield_->GetPreferredSize().height() +
+ (kTextfieldVerticalPadding - kWrapperBorderSize) * 2);
+ return gfx::Size(size, size);
+}
+} // namespace
PasswordGenerationBubbleView::PasswordGenerationBubbleView(
- const gfx::Rect& anchor_rect,
const webkit::forms::PasswordForm& form,
+ const gfx::Rect& anchor_rect,
views::View* anchor_view,
content::RenderViewHost* render_view_host,
+ PasswordManager* password_manager,
autofill::PasswordGenerator* password_generator,
content::PageNavigator* navigator,
- PasswordManager* password_manager)
+ ui::ThemeProvider* theme_provider)
: BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_LEFT),
+ title_label_(NULL),
accept_button_(NULL),
- text_field_(NULL),
- anchor_rect_(anchor_rect),
+ textfield_(NULL),
form_(form),
+ anchor_rect_(anchor_rect),
render_view_host_(render_view_host),
+ password_manager_(password_manager),
password_generator_(password_generator),
navigator_(navigator),
- password_manager_(password_manager) {}
+ theme_provider_(theme_provider) {}
PasswordGenerationBubbleView::~PasswordGenerationBubbleView() {}
void PasswordGenerationBubbleView::Init() {
+ set_margins(gfx::Insets(kBubbleMargin, kBubbleMargin,
+ kBubbleMargin, kBubbleMargin));
+
// TODO(gcasto): Localize text after we have finalized the UI.
- // crbug.com/118062
+ // crbug.com/118062.
+ gfx::Font label_font =
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
+ label_font = label_font.DeriveFont(2);
+ title_label_ = new views::Label(ASCIIToUTF16("Password Suggestion"),
+ label_font);
+ AddChildView(title_label_);
+
+ regenerate_button_ = new views::ImageButton(this);
+ regenerate_button_->SetImage(
+ views::CustomButton::BS_NORMAL,
+ theme_provider_->GetImageSkiaNamed(IDR_RELOAD));
+ regenerate_button_->SetImage(
+ views::CustomButton::BS_HOT,
+ theme_provider_->GetImageSkiaNamed(IDR_RELOAD));
+ regenerate_button_->SetImage(
+ views::CustomButton::BS_PUSHED,
+ theme_provider_->GetImageSkiaNamed(IDR_RELOAD));
+
+ textfield_ = new views::Textfield();
+ gfx::Font textfield_font =
+ ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
+ textfield_font = textfield_font.DeriveFont(2, gfx::Font::BOLD);
+ textfield_->SetFont(textfield_font);
+ textfield_->set_default_width_in_chars(kDefaultTextFieldChars);
+ textfield_->SetText(ASCIIToUTF16(password_generator_->Generate()));
+
+ textfield_wrapper_ = new TextfieldWrapper(textfield_,
+ regenerate_button_);
+ AddChildView(textfield_wrapper_);
+
accept_button_ = new views::NativeTextButton(this,
- ASCIIToUTF16("Try It"));
-
- text_field_ = new views::Textfield();
- text_field_->SetText(
- ASCIIToUTF16(password_generator_->Generate()));
-
- views::Label* title_label = new views::Label(
- ASCIIToUTF16("Password Suggestion"));
-
- views::Link* learn_more_link = new views::Link(
- l10n_util::GetStringUTF16(IDS_LEARN_MORE));
- learn_more_link->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- learn_more_link->set_listener(this);
-
- GridLayout* layout = new GridLayout(this);
- SetLayoutManager(layout);
-
- // Title row.
- ColumnSet* cs = layout->AddColumnSet(0);
- cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 100);
- cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
- cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 0);
-
- // Input row
- cs = layout->AddColumnSet(1);
- cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 100);
- cs->AddPaddingColumn(1, views::kRelatedControlHorizontalSpacing);
- cs->AddColumn(GridLayout::TRAILING, GridLayout::CENTER, 0,
- GridLayout::USE_PREF, 0, 0);
-
- layout->StartRow(0, 0);
- layout->AddView(title_label);
- layout->AddView(learn_more_link);
-
- layout->StartRow(0, 1);
- layout->AddView(text_field_);
- layout->AddView(accept_button_);
+ ASCIIToUTF16("Try it"));
+ AddChildView(accept_button_);
+}
+
+void PasswordGenerationBubbleView::Layout() {
+ // We have the title label shifted up to make the borders look more uniform.
+ title_label_->SetPosition(gfx::Point(0, kTitleLabelVerticalOffset));
+ title_label_->SizeToPreferredSize();
+
+ int y = title_label_->GetPreferredSize().height() + kVerticalPadding;
+
+ textfield_wrapper_->SetPosition(gfx::Point(0, y));
+ textfield_wrapper_->SizeToPreferredSize();
+
+ int button_x = (textfield_wrapper_->GetPreferredSize().width() +
+ kButtonHorizontalSpacing);
+ accept_button_->SetBounds(
+ button_x,
+ y - kWrapperBorderSize,
+ kButtonWidth,
+ textfield_wrapper_->GetPreferredSize().height() + kWrapperBorderSize * 2);
+}
+
+gfx::Size PasswordGenerationBubbleView::GetPreferredSize() {
+ int width = (textfield_wrapper_->GetPreferredSize().width() +
+ kButtonHorizontalSpacing +
+ kButtonWidth - 1);
+ int height = (title_label_->GetPreferredSize().height() +
+ textfield_wrapper_->GetPreferredSize().height() +
+ kVerticalPadding);
+ return gfx::Size(width, height);
}
gfx::Rect PasswordGenerationBubbleView::GetAnchorRect() {
@@ -100,21 +218,16 @@ void PasswordGenerationBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (sender == accept_button_) {
render_view_host_->Send(new AutofillMsg_GeneratedPasswordAccepted(
- render_view_host_->GetRoutingID(), text_field_->text()));
+ render_view_host_->GetRoutingID(), textfield_->text()));
password_manager_->SetFormHasGeneratedPassword(form_);
StartFade(false);
}
-}
-
-void PasswordGenerationBubbleView::LinkClicked(views::Link* source,
- int event_flags) {
- content::OpenURLParams params(
- GURL(chrome::kAutoPasswordGenerationLearnMoreURL), content::Referrer(),
- NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, false);
- navigator_->OpenURL(params);
- StartFade(false);
+ if (sender == regenerate_button_) {
+ textfield_->SetText(
+ ASCIIToUTF16(password_generator_->Generate()));
+ }
}
views::View* PasswordGenerationBubbleView::GetInitiallyFocusedView() {
- return text_field_;
+ return textfield_;
}
« no previous file with comments | « chrome/browser/ui/views/password_generation_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698