| 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/autofill/autofill_dialog_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_dialog_views.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 // It exists to circumvent shortcomings of GridLayout and BoxLayout (namely that | 154 // It exists to circumvent shortcomings of GridLayout and BoxLayout (namely that |
| 155 // the former doesn't fully respect child visibility, and that the latter won't | 155 // the former doesn't fully respect child visibility, and that the latter won't |
| 156 // expand a single child). | 156 // expand a single child). |
| 157 class SectionRowView : public views::View { | 157 class SectionRowView : public views::View { |
| 158 public: | 158 public: |
| 159 SectionRowView() { SetBorder(views::Border::CreateEmptyBorder(10, 0, 0, 0)); } | 159 SectionRowView() { SetBorder(views::Border::CreateEmptyBorder(10, 0, 0, 0)); } |
| 160 | 160 |
| 161 virtual ~SectionRowView() {} | 161 virtual ~SectionRowView() {} |
| 162 | 162 |
| 163 // views::View implementation: | 163 // views::View implementation: |
| 164 virtual gfx::Size GetPreferredSize() const OVERRIDE { | 164 virtual gfx::Size GetPreferredSize() const override { |
| 165 int height = 0; | 165 int height = 0; |
| 166 int width = 0; | 166 int width = 0; |
| 167 for (int i = 0; i < child_count(); ++i) { | 167 for (int i = 0; i < child_count(); ++i) { |
| 168 if (child_at(i)->visible()) { | 168 if (child_at(i)->visible()) { |
| 169 if (width > 0) | 169 if (width > 0) |
| 170 width += kAroundTextPadding; | 170 width += kAroundTextPadding; |
| 171 | 171 |
| 172 gfx::Size size = child_at(i)->GetPreferredSize(); | 172 gfx::Size size = child_at(i)->GetPreferredSize(); |
| 173 height = std::max(height, size.height()); | 173 height = std::max(height, size.height()); |
| 174 width += size.width(); | 174 width += size.width(); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 gfx::Insets insets = GetInsets(); | 178 gfx::Insets insets = GetInsets(); |
| 179 return gfx::Size(width + insets.width(), height + insets.height()); | 179 return gfx::Size(width + insets.width(), height + insets.height()); |
| 180 } | 180 } |
| 181 | 181 |
| 182 virtual void Layout() OVERRIDE { | 182 virtual void Layout() override { |
| 183 const gfx::Rect bounds = GetContentsBounds(); | 183 const gfx::Rect bounds = GetContentsBounds(); |
| 184 | 184 |
| 185 // Icon is left aligned. | 185 // Icon is left aligned. |
| 186 int start_x = bounds.x(); | 186 int start_x = bounds.x(); |
| 187 views::View* icon = child_at(0); | 187 views::View* icon = child_at(0); |
| 188 if (icon->visible()) { | 188 if (icon->visible()) { |
| 189 icon->SizeToPreferredSize(); | 189 icon->SizeToPreferredSize(); |
| 190 icon->SetX(start_x); | 190 icon->SetX(start_x); |
| 191 icon->SetY(bounds.y() + | 191 icon->SetY(bounds.y() + |
| 192 (bounds.height() - icon->bounds().height()) / 2); | 192 (bounds.height() - icon->bounds().height()) / 2); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 215 DISALLOW_COPY_AND_ASSIGN(SectionRowView); | 215 DISALLOW_COPY_AND_ASSIGN(SectionRowView); |
| 216 }; | 216 }; |
| 217 | 217 |
| 218 // A view that propagates visibility and preferred size changes. | 218 // A view that propagates visibility and preferred size changes. |
| 219 class LayoutPropagationView : public views::View { | 219 class LayoutPropagationView : public views::View { |
| 220 public: | 220 public: |
| 221 LayoutPropagationView() {} | 221 LayoutPropagationView() {} |
| 222 virtual ~LayoutPropagationView() {} | 222 virtual ~LayoutPropagationView() {} |
| 223 | 223 |
| 224 protected: | 224 protected: |
| 225 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE { | 225 virtual void ChildVisibilityChanged(views::View* child) override { |
| 226 PreferredSizeChanged(); | 226 PreferredSizeChanged(); |
| 227 } | 227 } |
| 228 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { | 228 virtual void ChildPreferredSizeChanged(views::View* child) override { |
| 229 PreferredSizeChanged(); | 229 PreferredSizeChanged(); |
| 230 } | 230 } |
| 231 | 231 |
| 232 private: | 232 private: |
| 233 DISALLOW_COPY_AND_ASSIGN(LayoutPropagationView); | 233 DISALLOW_COPY_AND_ASSIGN(LayoutPropagationView); |
| 234 }; | 234 }; |
| 235 | 235 |
| 236 // A View for a single notification banner. | 236 // A View for a single notification banner. |
| 237 class NotificationView : public views::View, | 237 class NotificationView : public views::View, |
| 238 public views::ButtonListener, | 238 public views::ButtonListener, |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 1, 0, 1, 0, data.GetBorderColor())); | 298 1, 0, 1, 0, data.GetBorderColor())); |
| 299 } | 299 } |
| 300 | 300 |
| 301 virtual ~NotificationView() {} | 301 virtual ~NotificationView() {} |
| 302 | 302 |
| 303 views::Checkbox* checkbox() { | 303 views::Checkbox* checkbox() { |
| 304 return checkbox_; | 304 return checkbox_; |
| 305 } | 305 } |
| 306 | 306 |
| 307 // views::View implementation. | 307 // views::View implementation. |
| 308 virtual gfx::Insets GetInsets() const OVERRIDE { | 308 virtual gfx::Insets GetInsets() const override { |
| 309 int vertical_padding = kNotificationPadding; | 309 int vertical_padding = kNotificationPadding; |
| 310 if (checkbox_) | 310 if (checkbox_) |
| 311 vertical_padding -= 3; | 311 vertical_padding -= 3; |
| 312 return gfx::Insets(vertical_padding, kDialogEdgePadding, | 312 return gfx::Insets(vertical_padding, kDialogEdgePadding, |
| 313 vertical_padding, kDialogEdgePadding); | 313 vertical_padding, kDialogEdgePadding); |
| 314 } | 314 } |
| 315 | 315 |
| 316 virtual int GetHeightForWidth(int width) const OVERRIDE { | 316 virtual int GetHeightForWidth(int width) const override { |
| 317 int label_width = width - GetInsets().width(); | 317 int label_width = width - GetInsets().width(); |
| 318 if (child_count() > 1) { | 318 if (child_count() > 1) { |
| 319 const views::View* tooltip_icon = child_at(1); | 319 const views::View* tooltip_icon = child_at(1); |
| 320 label_width -= tooltip_icon->GetPreferredSize().width() + | 320 label_width -= tooltip_icon->GetPreferredSize().width() + |
| 321 kDialogEdgePadding; | 321 kDialogEdgePadding; |
| 322 } | 322 } |
| 323 | 323 |
| 324 return child_at(0)->GetHeightForWidth(label_width) + GetInsets().height(); | 324 return child_at(0)->GetHeightForWidth(label_width) + GetInsets().height(); |
| 325 } | 325 } |
| 326 | 326 |
| 327 virtual void Layout() OVERRIDE { | 327 virtual void Layout() override { |
| 328 // Surprisingly, GetContentsBounds() doesn't consult GetInsets(). | 328 // Surprisingly, GetContentsBounds() doesn't consult GetInsets(). |
| 329 gfx::Rect bounds = GetLocalBounds(); | 329 gfx::Rect bounds = GetLocalBounds(); |
| 330 bounds.Inset(GetInsets()); | 330 bounds.Inset(GetInsets()); |
| 331 int right_bound = bounds.right(); | 331 int right_bound = bounds.right(); |
| 332 | 332 |
| 333 if (child_count() > 1) { | 333 if (child_count() > 1) { |
| 334 // The icon takes up the entire vertical space and an extra 20px on | 334 // The icon takes up the entire vertical space and an extra 20px on |
| 335 // each side. This increases the hover target for the tooltip. | 335 // each side. This increases the hover target for the tooltip. |
| 336 views::View* tooltip_icon = child_at(1); | 336 views::View* tooltip_icon = child_at(1); |
| 337 gfx::Size icon_size = tooltip_icon->GetPreferredSize(); | 337 gfx::Size icon_size = tooltip_icon->GetPreferredSize(); |
| 338 int icon_width = icon_size.width() + kDialogEdgePadding; | 338 int icon_width = icon_size.width() + kDialogEdgePadding; |
| 339 right_bound -= icon_width; | 339 right_bound -= icon_width; |
| 340 tooltip_icon->SetBounds( | 340 tooltip_icon->SetBounds( |
| 341 right_bound, 0, | 341 right_bound, 0, |
| 342 icon_width + kDialogEdgePadding, GetLocalBounds().height()); | 342 icon_width + kDialogEdgePadding, GetLocalBounds().height()); |
| 343 } | 343 } |
| 344 | 344 |
| 345 child_at(0)->SetBounds(bounds.x(), bounds.y(), | 345 child_at(0)->SetBounds(bounds.x(), bounds.y(), |
| 346 right_bound - bounds.x(), bounds.height()); | 346 right_bound - bounds.x(), bounds.height()); |
| 347 } | 347 } |
| 348 | 348 |
| 349 // views::ButtonListener implementation. | 349 // views::ButtonListener implementation. |
| 350 virtual void ButtonPressed(views::Button* sender, | 350 virtual void ButtonPressed(views::Button* sender, |
| 351 const ui::Event& event) OVERRIDE { | 351 const ui::Event& event) override { |
| 352 DCHECK_EQ(sender, checkbox_); | 352 DCHECK_EQ(sender, checkbox_); |
| 353 delegate_->NotificationCheckboxStateChanged(data_.type(), | 353 delegate_->NotificationCheckboxStateChanged(data_.type(), |
| 354 checkbox_->checked()); | 354 checkbox_->checked()); |
| 355 } | 355 } |
| 356 | 356 |
| 357 // views::StyledLabelListener implementation. | 357 // views::StyledLabelListener implementation. |
| 358 virtual void StyledLabelLinkClicked(const gfx::Range& range, int event_flags) | 358 virtual void StyledLabelLinkClicked(const gfx::Range& range, int event_flags) |
| 359 OVERRIDE { | 359 override { |
| 360 delegate_->LinkClicked(data_.link_url()); | 360 delegate_->LinkClicked(data_.link_url()); |
| 361 } | 361 } |
| 362 | 362 |
| 363 private: | 363 private: |
| 364 // The model data for this notification. | 364 // The model data for this notification. |
| 365 DialogNotification data_; | 365 DialogNotification data_; |
| 366 | 366 |
| 367 // The delegate that handles interaction with |this|. | 367 // The delegate that handles interaction with |this|. |
| 368 AutofillDialogViewDelegate* delegate_; | 368 AutofillDialogViewDelegate* delegate_; |
| 369 | 369 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 392 | 392 |
| 393 for (size_t i = 0; i < 3; ++i) { | 393 for (size_t i = 0; i < 3; ++i) { |
| 394 container_->AddChildView( | 394 container_->AddChildView( |
| 395 new views::Label(base::ASCIIToUTF16("."), font_list)); | 395 new views::Label(base::ASCIIToUTF16("."), font_list)); |
| 396 } | 396 } |
| 397 } | 397 } |
| 398 | 398 |
| 399 virtual ~LoadingAnimationView() {} | 399 virtual ~LoadingAnimationView() {} |
| 400 | 400 |
| 401 // views::View implementation. | 401 // views::View implementation. |
| 402 virtual void SetVisible(bool visible) OVERRIDE { | 402 virtual void SetVisible(bool visible) override { |
| 403 if (visible) | 403 if (visible) |
| 404 animation_->Start(); | 404 animation_->Start(); |
| 405 else | 405 else |
| 406 animation_->Reset(); | 406 animation_->Reset(); |
| 407 | 407 |
| 408 views::View::SetVisible(visible); | 408 views::View::SetVisible(visible); |
| 409 } | 409 } |
| 410 | 410 |
| 411 virtual void Layout() OVERRIDE { | 411 virtual void Layout() override { |
| 412 gfx::Size container_size = container_->GetPreferredSize(); | 412 gfx::Size container_size = container_->GetPreferredSize(); |
| 413 gfx::Rect container_bounds((width() - container_size.width()) / 2, | 413 gfx::Rect container_bounds((width() - container_size.width()) / 2, |
| 414 (height() - container_size.height()) / 2, | 414 (height() - container_size.height()) / 2, |
| 415 container_size.width(), | 415 container_size.width(), |
| 416 container_size.height()); | 416 container_size.height()); |
| 417 container_->SetBoundsRect(container_bounds); | 417 container_->SetBoundsRect(container_bounds); |
| 418 container_->Layout(); | 418 container_->Layout(); |
| 419 | 419 |
| 420 for (size_t i = 0; i < 3; ++i) { | 420 for (size_t i = 0; i < 3; ++i) { |
| 421 views::View* dot = container_->child_at(i + 1); | 421 views::View* dot = container_->child_at(i + 1); |
| 422 dot->SetY(dot->y() + animation_->GetCurrentValueForDot(i)); | 422 dot->SetY(dot->y() + animation_->GetCurrentValueForDot(i)); |
| 423 } | 423 } |
| 424 } | 424 } |
| 425 | 425 |
| 426 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE { | 426 virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) override { |
| 427 set_background(views::Background::CreateSolidBackground( | 427 set_background(views::Background::CreateSolidBackground( |
| 428 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); | 428 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground))); |
| 429 } | 429 } |
| 430 | 430 |
| 431 // gfx::AnimationDelegate implementation. | 431 // gfx::AnimationDelegate implementation. |
| 432 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE { | 432 virtual void AnimationProgressed(const gfx::Animation* animation) override { |
| 433 DCHECK_EQ(animation, animation_.get()); | 433 DCHECK_EQ(animation, animation_.get()); |
| 434 Layout(); | 434 Layout(); |
| 435 } | 435 } |
| 436 | 436 |
| 437 private: | 437 private: |
| 438 // Contains the "Loading" label and the dots. | 438 // Contains the "Loading" label and the dots. |
| 439 views::View* container_; | 439 views::View* container_; |
| 440 | 440 |
| 441 scoped_ptr<LoadingAnimation> animation_; | 441 scoped_ptr<LoadingAnimation> animation_; |
| 442 | 442 |
| 443 DISALLOW_COPY_AND_ASSIGN(LoadingAnimationView); | 443 DISALLOW_COPY_AND_ASSIGN(LoadingAnimationView); |
| 444 }; | 444 }; |
| 445 | 445 |
| 446 // Gets either the Combobox or ExpandingTextfield that is an ancestor (including | 446 // Gets either the Combobox or ExpandingTextfield that is an ancestor (including |
| 447 // self) of |view|. | 447 // self) of |view|. |
| 448 views::View* GetAncestralInputView(views::View* view) { | 448 views::View* GetAncestralInputView(views::View* view) { |
| 449 if (view->GetClassName() == views::Combobox::kViewClassName) | 449 if (view->GetClassName() == views::Combobox::kViewClassName) |
| 450 return view; | 450 return view; |
| 451 | 451 |
| 452 return view->GetAncestorWithClassName(ExpandingTextfield::kViewClassName); | 452 return view->GetAncestorWithClassName(ExpandingTextfield::kViewClassName); |
| 453 } | 453 } |
| 454 | 454 |
| 455 // A class that informs |delegate_| when an unhandled mouse press occurs. | 455 // A class that informs |delegate_| when an unhandled mouse press occurs. |
| 456 class MousePressedHandler : public ui::EventHandler { | 456 class MousePressedHandler : public ui::EventHandler { |
| 457 public: | 457 public: |
| 458 explicit MousePressedHandler(AutofillDialogViewDelegate* delegate) | 458 explicit MousePressedHandler(AutofillDialogViewDelegate* delegate) |
| 459 : delegate_(delegate) {} | 459 : delegate_(delegate) {} |
| 460 | 460 |
| 461 // ui::EventHandler implementation. | 461 // ui::EventHandler implementation. |
| 462 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 462 virtual void OnMouseEvent(ui::MouseEvent* event) override { |
| 463 if (event->type() == ui::ET_MOUSE_PRESSED && !event->handled()) | 463 if (event->type() == ui::ET_MOUSE_PRESSED && !event->handled()) |
| 464 delegate_->FocusMoved(); | 464 delegate_->FocusMoved(); |
| 465 } | 465 } |
| 466 | 466 |
| 467 private: | 467 private: |
| 468 AutofillDialogViewDelegate* const delegate_; | 468 AutofillDialogViewDelegate* const delegate_; |
| 469 | 469 |
| 470 DISALLOW_COPY_AND_ASSIGN(MousePressedHandler); | 470 DISALLOW_COPY_AND_ASSIGN(MousePressedHandler); |
| 471 }; | 471 }; |
| 472 | 472 |
| (...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2503 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) | 2503 AutofillDialogViews::DetailsGroup::DetailsGroup(DialogSection section) |
| 2504 : section(section), | 2504 : section(section), |
| 2505 container(NULL), | 2505 container(NULL), |
| 2506 manual_input(NULL), | 2506 manual_input(NULL), |
| 2507 suggested_info(NULL), | 2507 suggested_info(NULL), |
| 2508 suggested_button(NULL) {} | 2508 suggested_button(NULL) {} |
| 2509 | 2509 |
| 2510 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} | 2510 AutofillDialogViews::DetailsGroup::~DetailsGroup() {} |
| 2511 | 2511 |
| 2512 } // namespace autofill | 2512 } // namespace autofill |
| OLD | NEW |