Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/profiles/profile_chooser_view.h" | 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/lifetime/application_lifetime.h" | 10 #include "chrome/browser/lifetime/application_lifetime.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 27 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 28 #include "components/signin/core/browser/signin_manager.h" | 28 #include "components/signin/core/browser/signin_manager.h" |
| 29 #include "components/signin/core/common/profile_management_switches.h" | 29 #include "components/signin/core/common/profile_management_switches.h" |
| 30 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
| 31 #include "grit/generated_resources.h" | 31 #include "grit/generated_resources.h" |
| 32 #include "grit/theme_resources.h" | 32 #include "grit/theme_resources.h" |
| 33 #include "third_party/skia/include/core/SkColor.h" | 33 #include "third_party/skia/include/core/SkColor.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/base/resource/resource_bundle.h" | 35 #include "ui/base/resource/resource_bundle.h" |
| 36 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
| 37 #include "ui/gfx/image/canvas_image_source.h" | |
| 37 #include "ui/gfx/image/image.h" | 38 #include "ui/gfx/image/image.h" |
| 38 #include "ui/gfx/image/image_skia.h" | 39 #include "ui/gfx/image/image_skia.h" |
| 39 #include "ui/gfx/text_elider.h" | 40 #include "ui/gfx/text_elider.h" |
| 40 #include "ui/native_theme/native_theme.h" | 41 #include "ui/native_theme/native_theme.h" |
| 41 #include "ui/views/controls/button/blue_button.h" | 42 #include "ui/views/controls/button/blue_button.h" |
| 42 #include "ui/views/controls/button/image_button.h" | 43 #include "ui/views/controls/button/image_button.h" |
| 43 #include "ui/views/controls/button/label_button.h" | 44 #include "ui/views/controls/button/label_button.h" |
| 44 #include "ui/views/controls/button/menu_button.h" | 45 #include "ui/views/controls/button/menu_button.h" |
| 45 #include "ui/views/controls/label.h" | 46 #include "ui/views/controls/label.h" |
| 46 #include "ui/views/controls/link.h" | 47 #include "ui/views/controls/link.h" |
| 47 #include "ui/views/controls/separator.h" | 48 #include "ui/views/controls/separator.h" |
| 48 #include "ui/views/controls/styled_label.h" | 49 #include "ui/views/controls/styled_label.h" |
| 49 #include "ui/views/controls/textfield/textfield.h" | 50 #include "ui/views/controls/textfield/textfield.h" |
| 50 #include "ui/views/controls/webview/webview.h" | 51 #include "ui/views/controls/webview/webview.h" |
| 51 #include "ui/views/layout/grid_layout.h" | 52 #include "ui/views/layout/grid_layout.h" |
| 52 #include "ui/views/layout/layout_constants.h" | 53 #include "ui/views/layout/layout_constants.h" |
| 53 #include "ui/views/widget/widget.h" | 54 #include "ui/views/widget/widget.h" |
| 54 | 55 |
| 55 namespace { | 56 namespace { |
| 56 | 57 |
| 57 // Helpers -------------------------------------------------------------------- | 58 // Helpers -------------------------------------------------------------------- |
| 58 | 59 |
| 59 const int kFixedMenuWidth = 250; | 60 const int kFixedMenuWidth = 250; |
| 60 const int kButtonHeight = 29; | 61 const int kButtonHeight = 29; |
| 61 const int kProfileAvatarTutorialShowMax = 5; | 62 const int kProfileAvatarTutorialShowMax = 5; |
| 62 const int kFixedGaiaViewHeight = 400; | 63 const int kFixedGaiaViewHeight = 400; |
| 63 const int kFixedGaiaViewWidth = 360; | 64 const int kFixedGaiaViewWidth = 360; |
| 64 const int kFixedAccountRemovalViewWidth = 280; | 65 const int kFixedAccountRemovalViewWidth = 280; |
| 66 const int kLargeImageSide = 88; | |
| 65 | 67 |
| 66 // Creates a GridLayout with a single column. This ensures that all the child | 68 // Creates a GridLayout with a single column. This ensures that all the child |
| 67 // views added get auto-expanded to fill the full width of the bubble. | 69 // views added get auto-expanded to fill the full width of the bubble. |
| 68 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 70 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
| 69 views::GridLayout* layout = new views::GridLayout(view); | 71 views::GridLayout* layout = new views::GridLayout(view); |
| 70 view->SetLayoutManager(layout); | 72 view->SetLayoutManager(layout); |
| 71 | 73 |
| 72 views::ColumnSet* columns = layout->AddColumnSet(0); | 74 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 73 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 75 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 74 views::GridLayout::FIXED, width, width); | 76 views::GridLayout::FIXED, width, width); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 91 | 93 |
| 92 views::Link* CreateLink(const base::string16& link_text, | 94 views::Link* CreateLink(const base::string16& link_text, |
| 93 views::LinkListener* listener) { | 95 views::LinkListener* listener) { |
| 94 views::Link* link_button = new views::Link(link_text); | 96 views::Link* link_button = new views::Link(link_text); |
| 95 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 97 link_button->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 96 link_button->SetUnderline(false); | 98 link_button->SetUnderline(false); |
| 97 link_button->set_listener(listener); | 99 link_button->set_listener(listener); |
| 98 return link_button; | 100 return link_button; |
| 99 } | 101 } |
| 100 | 102 |
| 103 class BlankImageSource : public gfx::CanvasImageSource { | |
|
sky
2014/04/23 20:40:53
Why do you need this? Can't you either set a null
noms (inactive)
2014/04/24 14:29:23
The placeholder image needs to have the same size
sky
2014/04/24 16:27:45
https://code.google.com/p/chromium/codesearch#chro
noms (inactive)
2014/04/24 17:06:57
AH, that makes sense. Thanks! Done.
On 2014/04/24
| |
| 104 public: | |
| 105 explicit BlankImageSource(const gfx::Size& size_in_dip) | |
| 106 : CanvasImageSource(size_in_dip, /*is_opaque =*/ false) { | |
| 107 } | |
| 108 virtual ~BlankImageSource() {} | |
| 109 | |
| 110 private: | |
| 111 // gfx::CanvasImageSource overrides: | |
| 112 virtual void Draw(gfx::Canvas* canvas) OVERRIDE { | |
| 113 canvas->DrawColor(SkColorSetARGB(0, 0, 0, 0)); | |
| 114 } | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(BlankImageSource); | |
| 117 }; | |
| 101 | 118 |
| 102 // BackgroundColorHoverButton ------------------------------------------------- | 119 // BackgroundColorHoverButton ------------------------------------------------- |
| 103 | 120 |
| 104 // A custom button that allows for setting a background color when hovered over. | 121 // A custom button that allows for setting a background color when hovered over. |
| 105 class BackgroundColorHoverButton : public views::LabelButton { | 122 class BackgroundColorHoverButton : public views::LabelButton { |
| 106 public: | 123 public: |
| 107 BackgroundColorHoverButton(views::ButtonListener* listener, | 124 BackgroundColorHoverButton(views::ButtonListener* listener, |
| 108 const base::string16& text, | 125 const base::string16& text, |
| 109 const gfx::ImageSkia& normal_icon, | 126 const gfx::ImageSkia& normal_icon, |
| 110 const gfx::ImageSkia& hover_icon); | 127 const gfx::ImageSkia& hover_icon); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 129 SetImage(STATE_NORMAL, normal_icon); | 146 SetImage(STATE_NORMAL, normal_icon); |
| 130 SetImage(STATE_HOVERED, hover_icon); | 147 SetImage(STATE_HOVERED, hover_icon); |
| 131 SetImage(STATE_PRESSED, hover_icon); | 148 SetImage(STATE_PRESSED, hover_icon); |
| 132 } | 149 } |
| 133 | 150 |
| 134 BackgroundColorHoverButton::~BackgroundColorHoverButton() {} | 151 BackgroundColorHoverButton::~BackgroundColorHoverButton() {} |
| 135 | 152 |
| 136 void BackgroundColorHoverButton::OnPaint(gfx::Canvas* canvas) { | 153 void BackgroundColorHoverButton::OnPaint(gfx::Canvas* canvas) { |
| 137 if ((state() == STATE_PRESSED) || (state() == STATE_HOVERED) || HasFocus()) { | 154 if ((state() == STATE_PRESSED) || (state() == STATE_HOVERED) || HasFocus()) { |
| 138 canvas->DrawColor(GetNativeTheme()->GetSystemColor( | 155 canvas->DrawColor(GetNativeTheme()->GetSystemColor( |
| 139 ui::NativeTheme::kColorId_MenuSeparatorColor)); | 156 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor)); |
| 140 } | 157 } |
| 141 LabelButton::OnPaint(canvas); | 158 LabelButton::OnPaint(canvas); |
| 142 } | 159 } |
| 143 | 160 |
| 144 } // namespace | 161 } // namespace |
| 145 | 162 |
| 146 | 163 |
| 147 // EditableProfilePhoto ------------------------------------------------- | 164 // EditableProfilePhoto ------------------------------------------------- |
| 148 | 165 |
| 149 // A custom Image control that shows a "change" button when moused over. | 166 // A custom Image control that shows a "change" button when moused over. |
| 150 class EditableProfilePhoto : public views::ImageView { | 167 class EditableProfilePhoto : public views::ImageView { |
| 151 public: | 168 public: |
| 152 EditableProfilePhoto(views::ButtonListener* listener, | 169 EditableProfilePhoto(views::ButtonListener* listener, |
| 153 const gfx::Image& icon, | 170 const gfx::Image& icon, |
| 154 bool is_editing_allowed) | 171 bool is_editing_allowed, |
| 172 const gfx::Rect& bounds) | |
| 155 : views::ImageView(), | 173 : views::ImageView(), |
| 156 change_photo_button_(NULL) { | 174 change_photo_button_(NULL) { |
| 157 const int kLargeImageSide = 64; | |
| 158 gfx::Image image = profiles::GetSizedAvatarIcon( | 175 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 159 icon, true, | 176 icon, true, |
| 160 kLargeImageSide + profiles::kAvatarIconPadding, | 177 kLargeImageSide + profiles::kAvatarIconPadding, |
| 161 kLargeImageSide + profiles::kAvatarIconPadding); | 178 kLargeImageSide + profiles::kAvatarIconPadding); |
| 162 SetImage(image.ToImageSkia()); | 179 SetImage(image.ToImageSkia()); |
| 180 SetBoundsRect(bounds); | |
| 163 | 181 |
| 164 if (!is_editing_allowed) | 182 if (!is_editing_allowed) |
| 165 return; | 183 return; |
| 166 | 184 |
| 167 set_notify_enter_exit_on_child(true); | 185 set_notify_enter_exit_on_child(true); |
| 168 | 186 |
| 169 // Button overlay that appears when hovering over the image. | 187 // Button overlay that appears when hovering over the image. |
| 170 change_photo_button_ = new views::LabelButton(listener, | 188 change_photo_button_ = new views::LabelButton(listener, |
| 171 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_CHANGE_PHOTO_BUTTON)); | 189 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_CHANGE_PHOTO_BUTTON)); |
| 172 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 190 change_photo_button_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 173 change_photo_button_->SetBorder(views::Border::NullBorder()); | 191 change_photo_button_->SetBorder(views::Border::NullBorder()); |
| 174 const SkColor color = SK_ColorWHITE; | 192 const SkColor color = SK_ColorWHITE; |
| 175 change_photo_button_->SetTextColor(views::Button::STATE_NORMAL, color); | 193 change_photo_button_->SetTextColor(views::Button::STATE_NORMAL, color); |
| 176 change_photo_button_->SetTextColor(views::Button::STATE_HOVERED, color); | 194 change_photo_button_->SetTextColor(views::Button::STATE_HOVERED, color); |
| 177 | 195 |
| 178 const SkColor kBackgroundColor = SkColorSetARGB(125, 0, 0, 0); | 196 const SkColor kBackgroundColor = SkColorSetARGB(125, 0, 0, 0); |
| 179 change_photo_button_->set_background( | 197 change_photo_button_->set_background( |
| 180 views::Background::CreateSolidBackground(kBackgroundColor)); | 198 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 181 // Need to take into account the border padding on the avatar. | 199 // Need to take into account the border padding on the avatar. |
| 182 const int kOverlayHeight = 20; | 200 const int kOverlayHeight = 20; |
| 183 change_photo_button_->SetBounds( | 201 change_photo_button_->SetBounds( |
| 184 profiles::kAvatarIconPadding, | 202 bounds.origin().x(), |
| 185 kLargeImageSide - kOverlayHeight, | 203 bounds.origin().y() + kLargeImageSide - kOverlayHeight, |
| 186 kLargeImageSide - profiles::kAvatarIconPadding, | 204 kLargeImageSide, |
| 187 kOverlayHeight); | 205 kOverlayHeight); |
| 188 change_photo_button_->SetVisible(false); | 206 change_photo_button_->SetVisible(false); |
| 189 AddChildView(change_photo_button_); | 207 AddChildView(change_photo_button_); |
| 190 } | 208 } |
| 191 | 209 |
| 192 views::LabelButton* change_photo_button() { return change_photo_button_; } | 210 views::LabelButton* change_photo_button() { return change_photo_button_; } |
| 193 | 211 |
| 194 private: | 212 private: |
| 195 // views::View: | 213 // views::View: |
| 196 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { | 214 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 219 public: | 237 public: |
| 220 EditableProfileName(views::TextfieldController* controller, | 238 EditableProfileName(views::TextfieldController* controller, |
| 221 const base::string16& text, | 239 const base::string16& text, |
| 222 bool is_editing_allowed) | 240 bool is_editing_allowed) |
| 223 : views::LabelButton(this, text), | 241 : views::LabelButton(this, text), |
| 224 profile_name_textfield_(NULL) { | 242 profile_name_textfield_(NULL) { |
| 225 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 243 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 226 const gfx::FontList& medium_font_list = | 244 const gfx::FontList& medium_font_list = |
| 227 rb->GetFontList(ui::ResourceBundle::MediumFont); | 245 rb->GetFontList(ui::ResourceBundle::MediumFont); |
| 228 SetFontList(medium_font_list); | 246 SetFontList(medium_font_list); |
| 229 SetBorder(views::Border::NullBorder()); | 247 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 230 | 248 |
| 231 if (!is_editing_allowed) | 249 if (!is_editing_allowed) |
| 232 return; | 250 return; |
| 233 | 251 |
| 234 SetImage(STATE_HOVERED, | 252 // Show an "edit" pencil icon when hovering over. In the default state, |
| 235 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER)); | 253 // we need to create an empty placeholder of the correct size, so that |
| 254 // the text doesn't jump around when the hovered icon appears. | |
| 255 gfx::ImageSkia hover_image = | |
| 256 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_HOVER); | |
| 257 SetImage(STATE_NORMAL, gfx::ImageSkia( | |
| 258 new BlankImageSource(hover_image.size()), | |
| 259 hover_image.size())); | |
| 260 SetImage(STATE_HOVERED, hover_image); | |
| 236 SetImage(STATE_PRESSED, | 261 SetImage(STATE_PRESSED, |
| 237 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED)); | 262 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_EDIT_PRESSED)); |
| 263 // To center the text, we need to offest it by the width of the icon we | |
| 264 // are adding. We need to also add a small top/bottom padding to account | |
| 265 // for the textfield's border. | |
| 266 SetBorder(views::Border::CreateEmptyBorder(2, hover_image.width(), 2, 0)); | |
| 238 | 267 |
| 239 // Textfield that overlaps the button. | 268 // Textfield that overlaps the button. |
| 240 profile_name_textfield_ = new views::Textfield(); | 269 profile_name_textfield_ = new views::Textfield(); |
| 241 profile_name_textfield_->set_controller(controller); | 270 profile_name_textfield_->set_controller(controller); |
| 242 profile_name_textfield_->SetFontList(medium_font_list); | 271 profile_name_textfield_->SetFontList(medium_font_list); |
| 272 profile_name_textfield_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 273 | |
| 243 profile_name_textfield_->SetVisible(false); | 274 profile_name_textfield_->SetVisible(false); |
| 244 AddChildView(profile_name_textfield_); | 275 AddChildView(profile_name_textfield_); |
| 245 } | 276 } |
| 246 | 277 |
| 247 views::Textfield* profile_name_textfield() { | 278 views::Textfield* profile_name_textfield() { |
| 248 return profile_name_textfield_; | 279 return profile_name_textfield_; |
| 249 } | 280 } |
| 250 | 281 |
| 251 // Hide the editable textfield to show the profile name button instead. | 282 // Hide the editable textfield to show the profile name button instead. |
| 252 void ShowReadOnlyView() { | 283 void ShowReadOnlyView() { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 273 // part of the new profile name typed in the textfield. | 304 // part of the new profile name typed in the textfield. |
| 274 return false; | 305 return false; |
| 275 } | 306 } |
| 276 | 307 |
| 277 virtual void Layout() OVERRIDE { | 308 virtual void Layout() OVERRIDE { |
| 278 if (profile_name_textfield_) | 309 if (profile_name_textfield_) |
| 279 profile_name_textfield_->SetBounds(0, 0, width(), height()); | 310 profile_name_textfield_->SetBounds(0, 0, width(), height()); |
| 280 // This layout trick keeps the text left-aligned and the icon right-aligned. | 311 // This layout trick keeps the text left-aligned and the icon right-aligned. |
| 281 SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 312 SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 282 views::LabelButton::Layout(); | 313 views::LabelButton::Layout(); |
| 283 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 314 label()->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 284 } | 315 } |
| 285 | 316 |
| 286 // Button that is shown when hovering over the image view. Can be NULL if | 317 // Textfield that is shown when editing the profile name. Can be NULL if |
| 287 // the profile name isn't allowed to be edited (e.g. for guest profiles). | 318 // the profile name isn't allowed to be edited (e.g. for guest profiles). |
| 288 views::Textfield* profile_name_textfield_; | 319 views::Textfield* profile_name_textfield_; |
| 289 | 320 |
| 290 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); | 321 DISALLOW_COPY_AND_ASSIGN(EditableProfileName); |
| 291 }; | 322 }; |
| 292 | 323 |
| 293 // A title card with one back button right aligned and one label center aligned. | 324 // A title card with one back button right aligned and one label center aligned. |
| 294 class TitleCard : public views::View { | 325 class TitleCard : public views::View { |
| 295 public: | 326 public: |
| 296 TitleCard(int message_id, views::ButtonListener* listener, | 327 TitleCard(int message_id, views::ButtonListener* listener, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); | 439 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()); |
| 409 if (oauth2_token_service) | 440 if (oauth2_token_service) |
| 410 oauth2_token_service->RemoveObserver(this); | 441 oauth2_token_service->RemoveObserver(this); |
| 411 } | 442 } |
| 412 | 443 |
| 413 void ProfileChooserView::ResetView() { | 444 void ProfileChooserView::ResetView() { |
| 414 manage_accounts_link_ = NULL; | 445 manage_accounts_link_ = NULL; |
| 415 signin_current_profile_link_ = NULL; | 446 signin_current_profile_link_ = NULL; |
| 416 users_button_ = NULL; | 447 users_button_ = NULL; |
| 417 lock_button_ = NULL; | 448 lock_button_ = NULL; |
| 418 add_account_button_ = NULL; | 449 add_account_link_ = NULL; |
| 419 current_profile_photo_ = NULL; | 450 current_profile_photo_ = NULL; |
| 420 current_profile_name_ = NULL; | 451 current_profile_name_ = NULL; |
| 421 tutorial_ok_button_ = NULL; | 452 tutorial_ok_button_ = NULL; |
| 422 tutorial_learn_more_link_ = NULL; | 453 tutorial_learn_more_link_ = NULL; |
| 423 tutorial_enable_new_profile_management_button_ = NULL; | 454 tutorial_enable_new_profile_management_button_ = NULL; |
| 424 account_removal_cancel_button_ = NULL; | 455 account_removal_cancel_button_ = NULL; |
| 425 gaia_signin_cancel_button_ = NULL; | 456 gaia_signin_cancel_button_ = NULL; |
| 426 open_other_profile_indexes_map_.clear(); | 457 open_other_profile_indexes_map_.clear(); |
| 427 current_profile_accounts_map_.clear(); | 458 current_profile_accounts_map_.clear(); |
| 428 tutorial_showing_ = false; | 459 tutorial_showing_ = false; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 // Disable button after clicking so that it doesn't get clicked twice and | 540 // Disable button after clicking so that it doesn't get clicked twice and |
| 510 // start a second action... which can crash Chrome. But don't disable if it | 541 // start a second action... which can crash Chrome. But don't disable if it |
| 511 // has no parent (like in tests) because that will also crash. | 542 // has no parent (like in tests) because that will also crash. |
| 512 if (sender->parent()) | 543 if (sender->parent()) |
| 513 sender->SetEnabled(false); | 544 sender->SetEnabled(false); |
| 514 | 545 |
| 515 if (sender == users_button_) { | 546 if (sender == users_button_) { |
| 516 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 547 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
| 517 } else if (sender == lock_button_) { | 548 } else if (sender == lock_button_) { |
| 518 profiles::LockProfile(browser_->profile()); | 549 profiles::LockProfile(browser_->profile()); |
| 519 } else if (sender == add_account_button_) { | |
| 520 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); | |
| 521 } else if (sender == tutorial_ok_button_) { | 550 } else if (sender == tutorial_ok_button_) { |
| 522 // If the user manually dismissed the tutorial, never show it again by | 551 // If the user manually dismissed the tutorial, never show it again by |
| 523 // setting the number of times shown to the maximum plus 1, so that later we | 552 // setting the number of times shown to the maximum plus 1, so that later we |
| 524 // could distinguish between the dismiss case and the case when the tutorial | 553 // could distinguish between the dismiss case and the case when the tutorial |
| 525 // is indeed shown for the maximum number of times. | 554 // is indeed shown for the maximum number of times. |
| 526 browser_->profile()->GetPrefs()->SetInteger( | 555 browser_->profile()->GetPrefs()->SetInteger( |
| 527 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); | 556 prefs::kProfileAvatarTutorialShown, kProfileAvatarTutorialShowMax + 1); |
| 528 ShowView(BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); | 557 ShowView(BUBBLE_VIEW_MODE_PROFILE_CHOOSER, avatar_menu_.get()); |
| 529 } else if (sender == tutorial_enable_new_profile_management_button_) { | 558 } else if (sender == tutorial_enable_new_profile_management_button_) { |
| 530 profiles::EnableNewProfileManagementPreview(); | 559 profiles::EnableNewProfileManagementPreview(); |
| 531 } else if (sender == remove_account_and_relaunch_button_) { | 560 } else if (sender == remove_account_and_relaunch_button_) { |
| 532 RemoveAccount(); | 561 RemoveAccount(); |
| 533 } else if (sender == account_removal_cancel_button_) { | 562 } else if (sender == account_removal_cancel_button_) { |
| 534 account_id_to_remove_.clear(); | 563 account_id_to_remove_.clear(); |
| 535 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); | 564 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); |
| 536 } else if (sender == gaia_signin_cancel_button_) { | 565 } else if (sender == gaia_signin_cancel_button_) { |
| 537 std::string primary_account = | 566 std::string primary_account = |
| 538 SigninManagerFactory::GetForProfile(browser_->profile())-> | 567 SigninManagerFactory::GetForProfile(browser_->profile())-> |
| 539 GetAuthenticatedUsername(); | 568 GetAuthenticatedUsername(); |
| 540 ShowView(primary_account.empty() ? BUBBLE_VIEW_MODE_PROFILE_CHOOSER : | 569 ShowView(primary_account.empty() ? BUBBLE_VIEW_MODE_PROFILE_CHOOSER : |
| 541 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | 570 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, |
| 542 avatar_menu_.get()); | 571 avatar_menu_.get()); |
| 543 } else if (current_profile_photo_ && | 572 } else if (current_profile_photo_ && |
| 544 sender == current_profile_photo_->change_photo_button()) { | 573 sender == current_profile_photo_->change_photo_button()) { |
| 545 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); | 574 avatar_menu_->EditProfile(avatar_menu_->GetActiveProfileIndex()); |
| 575 } else if (sender == signin_current_profile_link_) { | |
| 576 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); | |
| 546 } else { | 577 } else { |
| 547 // One of the "other profiles" buttons was pressed. | 578 // Either one of the "other profiles", or one of the profile accounts |
| 548 ButtonIndexes::const_iterator match = | 579 // buttons was pressed. |
| 580 ButtonIndexes::const_iterator profile_match = | |
| 549 open_other_profile_indexes_map_.find(sender); | 581 open_other_profile_indexes_map_.find(sender); |
| 550 DCHECK(match != open_other_profile_indexes_map_.end()); | 582 if (profile_match != open_other_profile_indexes_map_.end()) { |
| 551 avatar_menu_->SwitchToProfile( | 583 avatar_menu_->SwitchToProfile( |
| 552 match->second, | 584 profile_match->second, |
| 553 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, | 585 ui::DispositionFromEventFlags(event.flags()) == NEW_WINDOW, |
| 554 ProfileMetrics::SWITCH_PROFILE_ICON); | 586 ProfileMetrics::SWITCH_PROFILE_ICON); |
| 587 } else { | |
| 588 // This was a profile accounts button. | |
| 589 AccountButtonIndexes::const_iterator account_match = | |
| 590 current_profile_accounts_map_.find(sender); | |
| 591 DCHECK(account_match != current_profile_accounts_map_.end()); | |
| 592 account_id_to_remove_ = account_match->second; | |
| 593 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); | |
| 594 } | |
| 555 } | 595 } |
| 556 } | 596 } |
| 557 | 597 |
| 558 void ProfileChooserView::OnMenuButtonClicked(views::View* source, | |
| 559 const gfx::Point& point) { | |
| 560 AccountButtonIndexes::const_iterator match = | |
| 561 current_profile_accounts_map_.find(source); | |
| 562 DCHECK(match != current_profile_accounts_map_.end()); | |
| 563 account_id_to_remove_ = match->second; | |
| 564 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_REMOVAL, avatar_menu_.get()); | |
| 565 } | |
| 566 | |
| 567 void ProfileChooserView::RemoveAccount() { | 598 void ProfileChooserView::RemoveAccount() { |
| 568 DCHECK(!account_id_to_remove_.empty()); | 599 DCHECK(!account_id_to_remove_.empty()); |
| 569 MutableProfileOAuth2TokenService* oauth2_token_service = | 600 MutableProfileOAuth2TokenService* oauth2_token_service = |
| 570 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( | 601 ProfileOAuth2TokenServiceFactory::GetPlatformSpecificForProfile( |
| 571 browser_->profile()); | 602 browser_->profile()); |
| 572 if (oauth2_token_service) | 603 if (oauth2_token_service) |
| 573 oauth2_token_service->RevokeCredentials(account_id_to_remove_); | 604 oauth2_token_service->RevokeCredentials(account_id_to_remove_); |
| 574 account_id_to_remove_.clear(); | 605 account_id_to_remove_.clear(); |
| 575 | 606 |
| 576 chrome::AttemptRestart(); | 607 chrome::AttemptRestart(); |
| 577 } | 608 } |
| 578 | 609 |
| 579 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { | 610 void ProfileChooserView::LinkClicked(views::Link* sender, int event_flags) { |
| 580 if (sender == manage_accounts_link_) { | 611 if (sender == manage_accounts_link_) { |
| 581 // ShowView() will DCHECK if this view is displayed for non signed-in users. | 612 // This link can either mean show/hide the account management view, |
| 582 ShowView(BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, avatar_menu_.get()); | 613 // depending on which view it is displayed. ShowView() will DCHECK if |
| 583 } else if (sender == tutorial_learn_more_link_) { | 614 // the account management view is displayed for non signed-in users. |
| 615 ShowView( | |
| 616 view_mode_ == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT ? | |
| 617 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : | |
| 618 BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT, | |
| 619 avatar_menu_.get()); | |
| 620 } else if (sender == add_account_link_) { | |
| 621 ShowView(BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT, avatar_menu_.get()); | |
| 622 } else { | |
| 623 DCHECK(sender == tutorial_learn_more_link_); | |
| 584 // TODO(guohui): update |learn_more_url| once it is decided. | 624 // TODO(guohui): update |learn_more_url| once it is decided. |
| 585 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); | 625 const GURL lear_more_url("https://support.google.com/chrome/?hl=en#to"); |
| 586 chrome::NavigateParams params( | 626 chrome::NavigateParams params( |
| 587 browser_->profile(), | 627 browser_->profile(), |
| 588 lear_more_url, | 628 lear_more_url, |
| 589 content::PAGE_TRANSITION_LINK); | 629 content::PAGE_TRANSITION_LINK); |
| 590 params.disposition = NEW_FOREGROUND_TAB; | 630 params.disposition = NEW_FOREGROUND_TAB; |
| 591 chrome::Navigate(¶ms); | 631 chrome::Navigate(¶ms); |
| 592 } else { | |
| 593 DCHECK(sender == signin_current_profile_link_); | |
| 594 ShowView(BUBBLE_VIEW_MODE_GAIA_SIGNIN, avatar_menu_.get()); | |
| 595 } | 632 } |
| 596 } | 633 } |
| 597 | 634 |
| 598 void ProfileChooserView::StyledLabelLinkClicked( | 635 void ProfileChooserView::StyledLabelLinkClicked( |
| 599 const gfx::Range& range, int event_flags) { | 636 const gfx::Range& range, int event_flags) { |
| 600 chrome::ShowSettings(browser_); | 637 chrome::ShowSettings(browser_); |
| 601 } | 638 } |
| 602 | 639 |
| 603 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, | 640 bool ProfileChooserView::HandleKeyEvent(views::Textfield* sender, |
| 604 const ui::KeyEvent& key_event) { | 641 const ui::KeyEvent& key_event) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 639 // Separate items into active and alternatives. | 676 // Separate items into active and alternatives. |
| 640 Indexes other_profiles; | 677 Indexes other_profiles; |
| 641 views::View* tutorial_view = NULL; | 678 views::View* tutorial_view = NULL; |
| 642 views::View* current_profile_view = NULL; | 679 views::View* current_profile_view = NULL; |
| 643 views::View* current_profile_accounts = NULL; | 680 views::View* current_profile_accounts = NULL; |
| 644 views::View* option_buttons_view = NULL; | 681 views::View* option_buttons_view = NULL; |
| 645 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 682 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 646 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 683 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 647 if (item.active) { | 684 if (item.active) { |
| 648 option_buttons_view = CreateOptionsView(item.signed_in); | 685 option_buttons_view = CreateOptionsView(item.signed_in); |
| 686 current_profile_view = CreateCurrentProfileView(item, false); | |
| 649 if (view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 687 if (view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
| 650 tutorial_view = switches::IsNewProfileManagement() ? | 688 tutorial_view = switches::IsNewProfileManagement() ? |
| 651 CreatePreviewEnabledTutorialView(item, tutorial_shown) : | 689 CreatePreviewEnabledTutorialView(item, tutorial_shown) : |
| 652 CreateNewProfileManagementPreviewView(); | 690 CreateNewProfileManagementPreviewView(); |
| 653 current_profile_view = CreateCurrentProfileView(item, false); | |
| 654 } else { | 691 } else { |
| 655 current_profile_view = CreateCurrentProfileEditableView(item); | |
| 656 current_profile_accounts = CreateCurrentProfileAccountsView(item); | 692 current_profile_accounts = CreateCurrentProfileAccountsView(item); |
| 657 } | 693 } |
| 658 } else { | 694 } else { |
| 659 other_profiles.push_back(i); | 695 other_profiles.push_back(i); |
| 660 } | 696 } |
| 661 } | 697 } |
| 662 | 698 |
| 663 if (tutorial_view) { | 699 if (tutorial_view) { |
| 664 layout->StartRow(1, 0); | 700 layout->StartRow(1, 0); |
| 665 layout->AddView(tutorial_view); | 701 layout->AddView(tutorial_view); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 682 DCHECK(current_profile_accounts); | 718 DCHECK(current_profile_accounts); |
| 683 layout->StartRow(0, 0); | 719 layout->StartRow(0, 0); |
| 684 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 720 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 685 layout->StartRow(1, 0); | 721 layout->StartRow(1, 0); |
| 686 layout->AddView(current_profile_accounts); | 722 layout->AddView(current_profile_accounts); |
| 687 } | 723 } |
| 688 | 724 |
| 689 layout->StartRow(0, 0); | 725 layout->StartRow(0, 0); |
| 690 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | 726 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); |
| 691 | 727 |
| 692 // Action buttons. | 728 // Option buttons. Only available with the new profile management flag. |
| 693 layout->StartRow(0, 0); | 729 if (switches::IsNewProfileManagement()) { |
| 694 layout->AddView(option_buttons_view); | 730 layout->StartRow(0, 0); |
| 731 layout->AddView(option_buttons_view); | |
| 732 } | |
| 695 | 733 |
| 696 return view; | 734 return view; |
| 697 } | 735 } |
| 698 | 736 |
| 699 views::View* ProfileChooserView::CreatePreviewEnabledTutorialView( | 737 views::View* ProfileChooserView::CreatePreviewEnabledTutorialView( |
| 700 const AvatarMenu::Item& current_avatar_item, | 738 const AvatarMenu::Item& current_avatar_item, |
| 701 bool tutorial_shown) { | 739 bool tutorial_shown) { |
| 702 if (!switches::IsNewProfileManagementPreviewEnabled()) | 740 if (!switches::IsNewProfileManagementPreviewEnabled()) |
| 703 return NULL; | 741 return NULL; |
| 704 | 742 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 815 layout_with_caret->AddView(view); | 853 layout_with_caret->AddView(view); |
| 816 layout_with_caret->StartRow(1, 0); | 854 layout_with_caret->StartRow(1, 0); |
| 817 layout_with_caret->AddView(padded_caret_view); | 855 layout_with_caret->AddView(padded_caret_view); |
| 818 return view_with_caret; | 856 return view_with_caret; |
| 819 } | 857 } |
| 820 | 858 |
| 821 views::View* ProfileChooserView::CreateCurrentProfileView( | 859 views::View* ProfileChooserView::CreateCurrentProfileView( |
| 822 const AvatarMenu::Item& avatar_item, | 860 const AvatarMenu::Item& avatar_item, |
| 823 bool is_guest) { | 861 bool is_guest) { |
| 824 views::View* view = new views::View(); | 862 views::View* view = new views::View(); |
| 825 views::GridLayout* layout = CreateDoubleColumnLayout(view); | 863 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; |
| 864 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | |
| 826 layout->SetInsets(views::kButtonVEdgeMarginNew, | 865 layout->SetInsets(views::kButtonVEdgeMarginNew, |
| 827 views::kButtonHEdgeMarginNew, | 866 views::kButtonHEdgeMarginNew, |
| 828 views::kButtonVEdgeMarginNew, | 867 views::kRelatedControlVerticalSpacing, |
| 829 views::kButtonHEdgeMarginNew); | 868 views::kButtonHEdgeMarginNew); |
| 830 | 869 |
| 831 current_profile_photo_ = | 870 // Profile icon, centered. |
| 832 new EditableProfilePhoto(this, avatar_item.icon, !is_guest); | 871 float x_offset = (column_width - kLargeImageSide) / 2; |
| 833 view->SetBoundsRect(current_profile_photo_->bounds()); | 872 current_profile_photo_ = new EditableProfilePhoto( |
| 873 this, avatar_item.icon, !is_guest, | |
| 874 gfx::Rect(x_offset, 0, kLargeImageSide, kLargeImageSide)); | |
| 875 layout->StartRow(1, 0); | |
| 876 layout->AddView(current_profile_photo_); | |
| 877 | |
| 878 // Profile name, centered. | |
| 834 current_profile_name_ = new EditableProfileName( | 879 current_profile_name_ = new EditableProfileName( |
| 835 this, profiles::GetAvatarNameForProfile(browser_->profile()), !is_guest); | 880 this, profiles::GetAvatarNameForProfile(browser_->profile()), !is_guest); |
| 836 layout->StartRow(1, 0); | 881 layout->StartRow(1, 0); |
| 837 layout->AddView(current_profile_photo_, 1, 3); | |
| 838 layout->AddView(current_profile_name_); | 882 layout->AddView(current_profile_name_); |
| 839 | 883 |
| 840 if (is_guest) { | 884 if (is_guest) |
| 841 layout->StartRow(1, 0); | 885 return view; |
| 842 layout->SkipColumns(1); | 886 |
| 843 layout->StartRow(1, 0); | 887 // The available links depend on the type of profile that is active. |
| 844 layout->SkipColumns(1); | 888 layout->StartRow(1, 0); |
| 845 } else if (avatar_item.signed_in) { | 889 if (avatar_item.signed_in) { |
| 846 manage_accounts_link_ = CreateLink( | 890 if (switches::IsNewProfileManagement()) { |
| 847 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON), | 891 base::string16 link_title = l10n_util::GetStringUTF16( |
| 848 this); | 892 view_mode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? |
| 849 layout->StartRow(1, 0); | 893 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| 850 layout->SkipColumns(1); | 894 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 851 layout->AddView(manage_accounts_link_); | 895 manage_accounts_link_ = CreateLink(link_title, this); |
| 852 layout->StartRow(1, 0); | 896 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 853 layout->SkipColumns(1); | 897 layout->AddView(manage_accounts_link_); |
| 898 } else { | |
| 899 views::Label* email_label = new views::Label(avatar_item.sync_state); | |
| 900 email_label->SetHorizontalAlignment(gfx::ALIGN_CENTER); | |
| 901 layout->AddView(email_label); | |
| 902 } | |
| 854 } else { | 903 } else { |
| 855 signin_current_profile_link_ = CreateLink( | 904 signin_current_profile_link_ = new views::BlueButton( |
| 856 l10n_util::GetStringFUTF16( | 905 this, l10n_util::GetStringFUTF16(IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 857 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 906 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 858 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | |
| 859 this); | |
| 860 layout->StartRow(1, 0); | |
| 861 layout->SkipColumns(1); | |
| 862 layout->AddView(signin_current_profile_link_); | 907 layout->AddView(signin_current_profile_link_); |
| 863 layout->StartRow(1, 0); | |
| 864 layout->SkipColumns(1); | |
| 865 } | 908 } |
| 866 | 909 |
| 867 return view; | 910 return view; |
| 868 } | 911 } |
| 869 | 912 |
| 870 views::View* ProfileChooserView::CreateCurrentProfileEditableView( | |
| 871 const AvatarMenu::Item& avatar_item) { | |
| 872 DCHECK(avatar_item.signed_in); | |
| 873 views::View* view = new views::View(); | |
| 874 views::GridLayout* layout = CreateDoubleColumnLayout(view); | |
| 875 layout->SetInsets(views::kButtonVEdgeMarginNew, | |
| 876 views::kButtonHEdgeMarginNew, | |
| 877 views::kButtonVEdgeMarginNew, | |
| 878 views::kButtonHEdgeMarginNew); | |
| 879 | |
| 880 current_profile_photo_ = | |
| 881 new EditableProfilePhoto(this, avatar_item.icon, true); | |
| 882 view->SetBoundsRect(current_profile_photo_->bounds()); | |
| 883 current_profile_name_ = new EditableProfileName( | |
| 884 this, profiles::GetAvatarNameForProfile(browser_->profile()), true); | |
| 885 | |
| 886 layout->StartRow(1, 0); | |
| 887 layout->AddView(current_profile_photo_, 1, 3); | |
| 888 layout->AddView(current_profile_name_); | |
| 889 | |
| 890 layout->StartRow(1, 0); | |
| 891 layout->SkipColumns(1); | |
| 892 | |
| 893 layout->StartRow(1, 0); | |
| 894 layout->SkipColumns(1); | |
| 895 return view; | |
| 896 } | |
| 897 | |
| 898 views::View* ProfileChooserView::CreateGuestProfileView() { | 913 views::View* ProfileChooserView::CreateGuestProfileView() { |
| 899 gfx::Image guest_icon = | 914 gfx::Image guest_icon = |
| 900 ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 915 ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 901 profiles::GetPlaceholderAvatarIconResourceID()); | 916 profiles::GetPlaceholderAvatarIconResourceID()); |
| 902 AvatarMenu::Item guest_avatar_item(0, 0, guest_icon); | 917 AvatarMenu::Item guest_avatar_item(0, 0, guest_icon); |
| 903 guest_avatar_item.active = true; | 918 guest_avatar_item.active = true; |
| 904 guest_avatar_item.name = l10n_util::GetStringUTF16( | 919 guest_avatar_item.name = l10n_util::GetStringUTF16( |
| 905 IDS_PROFILES_GUEST_PROFILE_NAME); | 920 IDS_PROFILES_GUEST_PROFILE_NAME); |
| 906 guest_avatar_item.signed_in = false; | 921 guest_avatar_item.signed_in = false; |
| 907 | 922 |
| 908 return CreateCurrentProfileView(guest_avatar_item, true); | 923 return CreateCurrentProfileView(guest_avatar_item, true); |
| 909 } | 924 } |
| 910 | 925 |
| 911 views::View* ProfileChooserView::CreateOtherProfilesView( | 926 views::View* ProfileChooserView::CreateOtherProfilesView( |
| 912 const Indexes& avatars_to_show) { | 927 const Indexes& avatars_to_show) { |
| 913 views::View* view = new views::View(); | 928 views::View* view = new views::View(); |
| 914 views::GridLayout* layout = CreateSingleColumnLayout( | 929 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 915 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); | 930 |
| 916 layout->SetInsets(0, views::kButtonHEdgeMarginNew, | |
| 917 views::kButtonVEdgeMarginNew, views::kButtonHEdgeMarginNew); | |
| 918 int num_avatars_to_show = avatars_to_show.size(); | 931 int num_avatars_to_show = avatars_to_show.size(); |
| 919 for (int i = 0; i < num_avatars_to_show; ++i) { | 932 for (int i = 0; i < num_avatars_to_show; ++i) { |
| 920 const size_t index = avatars_to_show[i]; | 933 const size_t index = avatars_to_show[i]; |
| 921 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); | 934 const AvatarMenu::Item& item = avatar_menu_->GetItemAt(index); |
| 922 const int kSmallImageSide = 32; | 935 const int kSmallImageSide = 32; |
| 923 | 936 |
| 924 gfx::Image image = profiles::GetSizedAvatarIcon( | 937 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 925 item.icon, true, | 938 item.icon, true, |
| 926 kSmallImageSide + profiles::kAvatarIconPadding, | 939 kSmallImageSide + profiles::kAvatarIconPadding, |
| 927 kSmallImageSide + profiles::kAvatarIconPadding); | 940 kSmallImageSide + profiles::kAvatarIconPadding); |
| 928 | 941 |
| 929 views::LabelButton* button = new views::LabelButton(this, item.name); | 942 views::LabelButton* button = new BackgroundColorHoverButton( |
| 943 this, | |
| 944 item.name, | |
| 945 *image.ToImageSkia(), | |
| 946 *image.ToImageSkia()); | |
| 947 button->set_min_size(gfx::Size( | |
| 948 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
| 949 | |
| 930 open_other_profile_indexes_map_[button] = index; | 950 open_other_profile_indexes_map_[button] = index; |
| 931 button->SetImage(views::Button::STATE_NORMAL, *image.ToImageSkia()); | |
| 932 button->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 933 ui::ResourceBundle::MediumFont)); | |
| 934 button->SetBorder(views::Border::NullBorder()); | |
| 935 | 951 |
| 936 layout->StartRow(1, 0); | 952 layout->StartRow(1, 0); |
| 953 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); | |
| 954 layout->StartRow(1, 0); | |
| 937 layout->AddView(button); | 955 layout->AddView(button); |
| 938 | |
| 939 // The last avatar in the list does not need any bottom padding. | |
| 940 if (i < num_avatars_to_show - 1) | |
| 941 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 942 } | 956 } |
| 943 | 957 |
| 944 return view; | 958 return view; |
| 945 } | 959 } |
| 946 | 960 |
| 947 views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { | 961 views::View* ProfileChooserView::CreateOptionsView(bool enable_lock) { |
| 948 views::View* view = new views::View(); | 962 views::View* view = new views::View(); |
| 949 views::GridLayout* layout; | 963 views::GridLayout* layout; |
| 950 | 964 |
| 951 // Only signed-in users have the ability to lock. | 965 // Only signed-in users have the ability to lock. |
| 952 if (enable_lock) { | 966 if (enable_lock) { |
| 953 layout = new views::GridLayout(view); | 967 layout = new views::GridLayout(view); |
| 954 views::ColumnSet* columns = layout->AddColumnSet(0); | 968 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 955 int width_of_lock_button = | 969 int width_of_lock_button = |
| 956 2 * views::kUnrelatedControlLargeHorizontalSpacing + 12; | 970 2 * views::kUnrelatedControlLargeHorizontalSpacing + 12; |
| 957 int width_of_users_button = kFixedMenuWidth - width_of_lock_button; | 971 int width_of_users_button = kFixedMenuWidth - width_of_lock_button; |
| 958 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 972 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 959 views::GridLayout::FIXED, width_of_users_button, | 973 views::GridLayout::FIXED, width_of_users_button, |
| 960 width_of_users_button); | 974 width_of_users_button); |
| 961 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, | 975 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, |
| 962 views::GridLayout::FIXED, width_of_lock_button, | 976 views::GridLayout::FIXED, width_of_lock_button, |
| 963 width_of_lock_button); | 977 width_of_lock_button); |
| 964 view->SetLayoutManager(layout); | 978 view->SetLayoutManager(layout); |
| 965 } else { | 979 } else { |
| 966 layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | 980 layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 967 } | 981 } |
| 968 | 982 |
| 969 // The horizontal padding will be set by each button individually, so that | |
| 970 // in the hovered state the button spans the entire parent view. | |
| 971 layout->SetInsets(views::kRelatedControlVerticalSpacing, 0, | |
| 972 views::kRelatedControlVerticalSpacing, 0); | |
| 973 | |
| 974 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 983 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 975 users_button_ = new BackgroundColorHoverButton( | 984 users_button_ = new BackgroundColorHoverButton( |
| 976 this, | 985 this, |
| 977 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU_BUTTON, | 986 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU_BUTTON, |
| 978 profiles::GetAvatarNameForProfile(browser_->profile())), | 987 profiles::GetAvatarNameForProfile(browser_->profile())), |
| 979 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR), | 988 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR), |
| 980 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); | 989 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_AVATAR)); |
| 990 users_button_->set_min_size(gfx::Size( | |
| 991 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
| 981 | 992 |
| 982 layout->StartRow(1, 0); | 993 layout->StartRow(1, 0); |
| 983 layout->AddView(users_button_); | 994 layout->AddView(users_button_); |
| 984 | 995 |
| 985 if (enable_lock) { | 996 if (enable_lock) { |
| 986 lock_button_ = new BackgroundColorHoverButton( | 997 lock_button_ = new BackgroundColorHoverButton( |
| 987 this, | 998 this, |
| 988 base::string16(), | 999 base::string16(), |
| 989 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK), | 1000 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK), |
| 990 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK)); | 1001 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_LOCK)); |
| 1002 lock_button_->set_min_size(gfx::Size( | |
| 1003 0, kButtonHeight + views::kRelatedControlVerticalSpacing)); | |
| 991 layout->AddView(lock_button_); | 1004 layout->AddView(lock_button_); |
| 992 } | 1005 } |
| 993 return view; | 1006 return view; |
| 994 } | 1007 } |
| 995 | 1008 |
| 996 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( | 1009 views::View* ProfileChooserView::CreateCurrentProfileAccountsView( |
| 997 const AvatarMenu::Item& avatar_item) { | 1010 const AvatarMenu::Item& avatar_item) { |
| 998 DCHECK(avatar_item.signed_in); | 1011 DCHECK(avatar_item.signed_in); |
| 999 views::View* view = new views::View(); | 1012 views::View* view = new views::View(); |
| 1000 int column_width = kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew; | 1013 view->set_background(views::Background::CreateSolidBackground( |
| 1001 views::GridLayout* layout = CreateSingleColumnLayout(view, column_width); | 1014 profiles::kAvatarBubbleAccountsBackgroundColor)); |
| 1002 layout->SetInsets(views::kButtonVEdgeMarginNew, | 1015 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
| 1003 views::kButtonHEdgeMarginNew, | |
| 1004 views::kButtonVEdgeMarginNew, | |
| 1005 views::kButtonHEdgeMarginNew); | |
| 1006 | 1016 |
| 1007 Profile* profile = browser_->profile(); | 1017 Profile* profile = browser_->profile(); |
| 1008 std::string primary_account = | 1018 std::string primary_account = |
| 1009 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 1019 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
| 1010 DCHECK(!primary_account.empty()); | 1020 DCHECK(!primary_account.empty()); |
| 1011 std::vector<std::string>accounts = | 1021 std::vector<std::string>accounts = |
| 1012 profiles::GetSecondaryAccountsForProfile(profile, primary_account); | 1022 profiles::GetSecondaryAccountsForProfile(profile, primary_account); |
| 1013 | 1023 |
| 1014 // The primary account should always be listed first. | 1024 // The primary account should always be listed first. |
| 1015 // TODO(rogerta): we still need to further differentiate the primary account | 1025 // TODO(rogerta): we still need to further differentiate the primary account |
| 1016 // from the others in the UI, so more work is likely required here: | 1026 // from the others in the UI, so more work is likely required here: |
| 1017 // crbug.com/311124. | 1027 // crbug.com/311124. |
| 1018 CreateAccountButton(layout, primary_account, true, column_width); | 1028 CreateAccountButton(layout, primary_account, true, kFixedMenuWidth); |
| 1019 for (size_t i = 0; i < accounts.size(); ++i) | 1029 for (size_t i = 0; i < accounts.size(); ++i) |
| 1020 CreateAccountButton(layout, accounts[i], false, column_width); | 1030 CreateAccountButton(layout, accounts[i], false, kFixedMenuWidth); |
| 1021 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 1031 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1022 | 1032 |
| 1023 add_account_button_ = new views::BlueButton( | 1033 add_account_link_ = CreateLink(l10n_util::GetStringFUTF16( |
| 1024 this, | 1034 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, avatar_item.name), this); |
| 1025 l10n_util::GetStringFUTF16(IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, | 1035 add_account_link_->SetBorder(views::Border::CreateEmptyBorder( |
| 1026 avatar_item.name)); | 1036 0, views::kButtonVEdgeMarginNew, |
| 1037 views::kRelatedControlVerticalSpacing, 0)); | |
| 1027 layout->StartRow(1, 0); | 1038 layout->StartRow(1, 0); |
| 1028 layout->AddView(add_account_button_); | 1039 layout->AddView(add_account_link_); |
| 1029 return view; | 1040 return view; |
| 1030 } | 1041 } |
| 1031 | 1042 |
| 1032 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, | 1043 void ProfileChooserView::CreateAccountButton(views::GridLayout* layout, |
| 1033 const std::string& account, | 1044 const std::string& account, |
| 1034 bool is_primary_account, | 1045 bool is_primary_account, |
| 1035 int width) { | 1046 int width) { |
| 1036 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1047 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
| 1037 const gfx::ImageSkia* menu_marker = | 1048 const gfx::ImageSkia* menu_marker = |
| 1038 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); | 1049 rb->GetImageNamed(IDR_CLOSE_1).ToImageSkia(); |
| 1039 // Use a MenuButtonListener and not a regular ButtonListener to be | 1050 |
| 1040 // able to distinguish between the unnamed "other profile" buttons and the | 1051 views::LabelButton* email_button = new BackgroundColorHoverButton( |
| 1041 // unnamed "multiple accounts" buttons. | 1052 this, |
| 1042 views::MenuButton* email_button = new views::MenuButton( | |
| 1043 NULL, | |
| 1044 gfx::ElideEmail(base::UTF8ToUTF16(account), | 1053 gfx::ElideEmail(base::UTF8ToUTF16(account), |
| 1045 rb->GetFontList(ui::ResourceBundle::BaseFont), | 1054 rb->GetFontList(ui::ResourceBundle::BaseFont), |
| 1046 width - menu_marker->width()), | 1055 width - menu_marker->width()), |
| 1047 this, | 1056 gfx::ImageSkia(), |
| 1048 true /* show_menu_marker */); | 1057 gfx::ImageSkia()); |
| 1049 email_button->SetBorder(views::Border::CreateEmptyBorder(0, 0, 0, 0)); | |
| 1050 email_button->set_menu_marker(menu_marker); | |
| 1051 if (!is_primary_account) | |
| 1052 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | |
| 1053 layout->StartRow(1, 0); | 1058 layout->StartRow(1, 0); |
| 1054 layout->AddView(email_button); | 1059 layout->AddView(email_button); |
| 1055 | 1060 |
| 1056 // Save the original email address, as the button text could be elided. | 1061 // Save the original email address, as the button text could be elided. |
| 1057 current_profile_accounts_map_[email_button] = account; | 1062 current_profile_accounts_map_[email_button] = account; |
| 1058 } | 1063 } |
| 1059 | 1064 |
| 1060 views::View* ProfileChooserView::CreateGaiaSigninView( | 1065 views::View* ProfileChooserView::CreateGaiaSigninView( |
| 1061 bool add_secondary_account) { | 1066 bool add_secondary_account) { |
| 1062 views::View* view = new views::View(); | 1067 views::View* view = new views::View(); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1168 | 1173 |
| 1169 views::View* ProfileChooserView::CreateNewProfileManagementPreviewView() { | 1174 views::View* ProfileChooserView::CreateNewProfileManagementPreviewView() { |
| 1170 return CreateTutorialView( | 1175 return CreateTutorialView( |
| 1171 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_TITLE), | 1176 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_TITLE), |
| 1172 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT), | 1177 l10n_util::GetStringUTF16(IDS_PROFILES_PREVIEW_TUTORIAL_CONTENT_TEXT), |
| 1173 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), | 1178 l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE), |
| 1174 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_TRY_BUTTON), | 1179 l10n_util::GetStringUTF16(IDS_PROFILES_TUTORIAL_TRY_BUTTON), |
| 1175 &tutorial_learn_more_link_, | 1180 &tutorial_learn_more_link_, |
| 1176 &tutorial_enable_new_profile_management_button_); | 1181 &tutorial_enable_new_profile_management_button_); |
| 1177 } | 1182 } |
| OLD | NEW |