| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/translate/translate_bubble_view.h" | 5 #include "chrome/browser/ui/views/translate/translate_bubble_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/base/models/combobox_model.h" | 34 #include "ui/base/models/combobox_model.h" |
| 35 #include "ui/base/models/simple_combobox_model.h" | 35 #include "ui/base/models/simple_combobox_model.h" |
| 36 #include "ui/base/resource/resource_bundle.h" | 36 #include "ui/base/resource/resource_bundle.h" |
| 37 #include "ui/resources/grit/ui_resources.h" | 37 #include "ui/resources/grit/ui_resources.h" |
| 38 #include "ui/views/bubble/bubble_frame_view.h" | 38 #include "ui/views/bubble/bubble_frame_view.h" |
| 39 #include "ui/views/controls/button/blue_button.h" | 39 #include "ui/views/controls/button/blue_button.h" |
| 40 #include "ui/views/controls/button/checkbox.h" | 40 #include "ui/views/controls/button/checkbox.h" |
| 41 #include "ui/views/controls/button/label_button.h" | 41 #include "ui/views/controls/button/label_button.h" |
| 42 #include "ui/views/controls/button/md_text_button.h" |
| 42 #include "ui/views/controls/button/menu_button.h" | 43 #include "ui/views/controls/button/menu_button.h" |
| 43 #include "ui/views/controls/combobox/combobox.h" | 44 #include "ui/views/controls/combobox/combobox.h" |
| 44 #include "ui/views/controls/label.h" | 45 #include "ui/views/controls/label.h" |
| 45 #include "ui/views/controls/link.h" | 46 #include "ui/views/controls/link.h" |
| 46 #include "ui/views/controls/styled_label.h" | 47 #include "ui/views/controls/styled_label.h" |
| 47 #include "ui/views/layout/box_layout.h" | 48 #include "ui/views/layout/box_layout.h" |
| 48 #include "ui/views/layout/grid_layout.h" | 49 #include "ui/views/layout/grid_layout.h" |
| 49 #include "ui/views/layout/layout_constants.h" | 50 #include "ui/views/layout/layout_constants.h" |
| 50 #include "ui/views/widget/widget.h" | 51 #include "ui/views/widget/widget.h" |
| 51 | 52 |
| 52 namespace { | 53 namespace { |
| 53 | 54 |
| 54 views::LabelButton* CreateBlueButton(views::ButtonListener* listener, | |
| 55 const base::string16& label, | |
| 56 int id) { | |
| 57 views::LabelButton* button = new views::BlueButton(listener, label); | |
| 58 button->set_id(id); | |
| 59 return button; | |
| 60 } | |
| 61 | |
| 62 views::LabelButton* CreateLabelButton(views::ButtonListener* listener, | |
| 63 const base::string16& label, | |
| 64 int id) { | |
| 65 views::LabelButton* button = new views::LabelButton(listener, label); | |
| 66 button->set_id(id); | |
| 67 button->SetStyle(views::Button::STYLE_BUTTON); | |
| 68 return button; | |
| 69 } | |
| 70 | |
| 71 views::Link* CreateLink(views::LinkListener* listener, | 55 views::Link* CreateLink(views::LinkListener* listener, |
| 72 const base::string16& text, | 56 int resource_id, |
| 73 int id) { | 57 int id) { |
| 74 views::Link* link = new views::Link(text); | 58 views::Link* link = new views::Link(l10n_util::GetStringUTF16(resource_id)); |
| 75 link->set_listener(listener); | 59 link->set_listener(listener); |
| 76 link->set_id(id); | 60 link->set_id(id); |
| 77 return link; | 61 return link; |
| 78 } | 62 } |
| 79 | 63 |
| 80 views::Link* CreateLink(views::LinkListener* listener, | |
| 81 int resource_id, | |
| 82 int id) { | |
| 83 return CreateLink(listener, l10n_util::GetStringUTF16(resource_id), id); | |
| 84 } | |
| 85 | |
| 86 // TODO(ftang) Restore icons in CreateViewAfterTranslate and CreateViewError | 64 // TODO(ftang) Restore icons in CreateViewAfterTranslate and CreateViewError |
| 87 // without causing layout issues; see http://crbug.com/610351 | 65 // without causing layout issues; see http://crbug.com/610351 |
| 88 void AddIconToLayout(views::GridLayout* layout) { | 66 void AddIconToLayout(views::GridLayout* layout) { |
| 89 views::ImageView* icon = new views::ImageView(); | 67 views::ImageView* icon = new views::ImageView(); |
| 90 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 68 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 91 icon->SetImage(bundle.GetImageNamed(IDR_TRANSLATE_ICON_BUBBLE).ToImageSkia()); | 69 icon->SetImage(bundle.GetImageNamed(IDR_TRANSLATE_ICON_BUBBLE).ToImageSkia()); |
| 92 layout->AddView(icon); | 70 layout->AddView(icon); |
| 93 } | 71 } |
| 94 | 72 |
| 95 bool Use2016Q2UI() { | 73 bool Use2016Q2UI() { |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 } | 600 } |
| 623 if (Use2016Q2UI()) { | 601 if (Use2016Q2UI()) { |
| 624 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); | 602 layout->AddPaddingRow(0, views::kPanelSubVerticalSpacing); |
| 625 } else { | 603 } else { |
| 626 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 604 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 627 } | 605 } |
| 628 | 606 |
| 629 layout->StartRow(0, COLUMN_SET_ID_CONTENT); | 607 layout->StartRow(0, COLUMN_SET_ID_CONTENT); |
| 630 views::LabelButton* accept_button = | 608 views::LabelButton* accept_button = |
| 631 Use2016Q2UI() | 609 Use2016Q2UI() |
| 632 ? CreateBlueButton( | 610 ? views::MdTextButton::CreateSecondaryUiBlueButton( |
| 633 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT), | 611 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT)) |
| 634 BUTTON_ID_TRANSLATE) | 612 : views::MdTextButton::CreateSecondaryUiButton( |
| 635 : CreateLabelButton( | 613 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT)); |
| 636 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT), | 614 accept_button->set_id(BUTTON_ID_TRANSLATE); |
| 637 BUTTON_ID_TRANSLATE); | |
| 638 layout->AddView(accept_button); | 615 layout->AddView(accept_button); |
| 639 accept_button->SetIsDefault(true); | 616 accept_button->SetIsDefault(true); |
| 640 if (Use2016Q2UI()) { | 617 if (Use2016Q2UI()) { |
| 641 denial_menu_button_ = new views::MenuButton( | 618 denial_menu_button_ = new views::MenuButton( |
| 642 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_OPTIONS_MENU_BUTTON), | 619 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_OPTIONS_MENU_BUTTON), |
| 643 this, true); | 620 this, true); |
| 644 denial_menu_button_->SetStyle(views::Button::STYLE_BUTTON); | 621 denial_menu_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 645 layout->AddView(denial_menu_button_); | 622 layout->AddView(denial_menu_button_); |
| 646 } else { | 623 } else { |
| 647 std::vector<base::string16> items( | 624 std::vector<base::string16> items( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 GridLayout::USE_PREF, 0, 0); | 675 GridLayout::USE_PREF, 0, 0); |
| 699 | 676 |
| 700 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); | 677 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); |
| 701 if (Use2016Q2UI()) | 678 if (Use2016Q2UI()) |
| 702 AddIconToLayout(layout); | 679 AddIconToLayout(layout); |
| 703 layout->AddView(label); | 680 layout->AddView(label); |
| 704 | 681 |
| 705 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 682 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 706 | 683 |
| 707 layout->StartRow(0, COLUMN_SET_ID_CONTENT); | 684 layout->StartRow(0, COLUMN_SET_ID_CONTENT); |
| 708 views::LabelButton* revert_button = CreateLabelButton( | 685 views::LabelButton* revert_button = |
| 709 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_REVERT), | 686 views::MdTextButton::CreateSecondaryUiButton( |
| 710 BUTTON_ID_SHOW_ORIGINAL); | 687 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_REVERT)); |
| 688 revert_button->set_id(BUTTON_ID_SHOW_ORIGINAL); |
| 711 revert_button->SetEnabled(false); | 689 revert_button->SetEnabled(false); |
| 712 layout->AddView(revert_button); | 690 layout->AddView(revert_button); |
| 713 | 691 |
| 714 return view; | 692 return view; |
| 715 } | 693 } |
| 716 | 694 |
| 717 views::View* TranslateBubbleView::CreateViewAfterTranslate() { | 695 views::View* TranslateBubbleView::CreateViewAfterTranslate() { |
| 718 views::Label* label = new views::Label( | 696 views::Label* label = new views::Label( |
| 719 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRANSLATED)); | 697 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRANSLATED)); |
| 720 | 698 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 746 GridLayout::USE_PREF, 0, 0); | 724 GridLayout::USE_PREF, 0, 0); |
| 747 | 725 |
| 748 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); | 726 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); |
| 749 layout->AddView(label); | 727 layout->AddView(label); |
| 750 layout->AddView( | 728 layout->AddView( |
| 751 CreateLink(this, IDS_TRANSLATE_BUBBLE_ADVANCED, LINK_ID_ADVANCED)); | 729 CreateLink(this, IDS_TRANSLATE_BUBBLE_ADVANCED, LINK_ID_ADVANCED)); |
| 752 | 730 |
| 753 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 731 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 754 | 732 |
| 755 layout->StartRow(0, COLUMN_SET_ID_CONTENT); | 733 layout->StartRow(0, COLUMN_SET_ID_CONTENT); |
| 756 layout->AddView(CreateLabelButton( | 734 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( |
| 757 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_REVERT), | 735 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_REVERT)); |
| 758 BUTTON_ID_SHOW_ORIGINAL)); | 736 button->set_id(BUTTON_ID_SHOW_ORIGINAL); |
| 737 layout->AddView(button); |
| 759 | 738 |
| 760 return view; | 739 return view; |
| 761 } | 740 } |
| 762 | 741 |
| 763 views::View* TranslateBubbleView::CreateViewError() { | 742 views::View* TranslateBubbleView::CreateViewError() { |
| 764 views::Label* label = new views::Label( | 743 views::Label* label = new views::Label( |
| 765 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_COULD_NOT_TRANSLATE)); | 744 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_COULD_NOT_TRANSLATE)); |
| 766 | 745 |
| 767 views::View* view = new views::View(); | 746 views::View* view = new views::View(); |
| 768 views::GridLayout* layout = new views::GridLayout(view); | 747 views::GridLayout* layout = new views::GridLayout(view); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 792 GridLayout::USE_PREF, 0, 0); | 771 GridLayout::USE_PREF, 0, 0); |
| 793 | 772 |
| 794 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); | 773 layout->StartRow(0, COLUMN_SET_ID_MESSAGE); |
| 795 layout->AddView(label); | 774 layout->AddView(label); |
| 796 layout->AddView( | 775 layout->AddView( |
| 797 CreateLink(this, IDS_TRANSLATE_BUBBLE_ADVANCED, LINK_ID_ADVANCED)); | 776 CreateLink(this, IDS_TRANSLATE_BUBBLE_ADVANCED, LINK_ID_ADVANCED)); |
| 798 | 777 |
| 799 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 778 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 800 | 779 |
| 801 layout->StartRow(0, COLUMN_SET_ID_CONTENT); | 780 layout->StartRow(0, COLUMN_SET_ID_CONTENT); |
| 802 layout->AddView(CreateLabelButton( | 781 views::LabelButton* button = views::MdTextButton::CreateSecondaryUiButton( |
| 803 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRY_AGAIN), | 782 this, l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_TRY_AGAIN)); |
| 804 BUTTON_ID_TRY_AGAIN)); | 783 button->set_id(BUTTON_ID_TRY_AGAIN); |
| 784 layout->AddView(button); |
| 805 | 785 |
| 806 return view; | 786 return view; |
| 807 } | 787 } |
| 808 | 788 |
| 809 // TODO(hajimehoshi): Revice this later to show a specific message for each | 789 // TODO(hajimehoshi): Revice this later to show a specific message for each |
| 810 // error. (crbug/307350) | 790 // error. (crbug/307350) |
| 811 views::View* TranslateBubbleView::CreateViewAdvanced() { | 791 views::View* TranslateBubbleView::CreateViewAdvanced() { |
| 812 views::Label* source_language_label = new views::Label( | 792 views::Label* source_language_label = new views::Label( |
| 813 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_PAGE_LANGUAGE)); | 793 l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_PAGE_LANGUAGE)); |
| 814 | 794 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 if (!is_in_incognito_window_) { | 862 if (!is_in_incognito_window_) { |
| 883 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 863 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 884 layout->StartRow(0, COLUMN_SET_ID_LANGUAGES); | 864 layout->StartRow(0, COLUMN_SET_ID_LANGUAGES); |
| 885 layout->SkipColumns(1); | 865 layout->SkipColumns(1); |
| 886 layout->AddView(advanced_always_translate_checkbox_); | 866 layout->AddView(advanced_always_translate_checkbox_); |
| 887 } | 867 } |
| 888 | 868 |
| 889 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); | 869 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
| 890 | 870 |
| 891 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); | 871 layout->StartRow(0, COLUMN_SET_ID_BUTTONS); |
| 872 // TODO(estade): this should use CreateExtraView(). |
| 892 layout->AddView(CreateLink(this, IDS_TRANSLATE_BUBBLE_LANGUAGE_SETTINGS, | 873 layout->AddView(CreateLink(this, IDS_TRANSLATE_BUBBLE_LANGUAGE_SETTINGS, |
| 893 LINK_ID_LANGUAGE_SETTINGS)); | 874 LINK_ID_LANGUAGE_SETTINGS)); |
| 894 advanced_done_button_ = | 875 advanced_done_button_ = |
| 895 Use2016Q2UI() | 876 Use2016Q2UI() ? views::MdTextButton::CreateSecondaryUiBlueButton( |
| 896 ? CreateBlueButton(this, l10n_util::GetStringUTF16(IDS_DONE), | 877 this, l10n_util::GetStringUTF16(IDS_DONE)) |
| 897 BUTTON_ID_DONE) | 878 : views::MdTextButton::CreateSecondaryUiButton( |
| 898 : CreateLabelButton(this, l10n_util::GetStringUTF16(IDS_DONE), | 879 this, l10n_util::GetStringUTF16(IDS_DONE)); |
| 899 BUTTON_ID_DONE); | 880 advanced_done_button_->set_id(BUTTON_ID_DONE); |
| 900 advanced_done_button_->SetIsDefault(true); | 881 advanced_done_button_->SetIsDefault(true); |
| 901 advanced_cancel_button_ = CreateLabelButton( | 882 advanced_cancel_button_ = views::MdTextButton::CreateSecondaryUiButton( |
| 902 this, l10n_util::GetStringUTF16(IDS_CANCEL), BUTTON_ID_CANCEL); | 883 this, l10n_util::GetStringUTF16(IDS_CANCEL)); |
| 884 advanced_cancel_button_->set_id(BUTTON_ID_CANCEL); |
| 885 // TODO(estade): this should be using GetDialogButtons(). |
| 903 layout->AddView(advanced_done_button_); | 886 layout->AddView(advanced_done_button_); |
| 904 layout->AddView(advanced_cancel_button_); | 887 layout->AddView(advanced_cancel_button_); |
| 905 | 888 |
| 906 UpdateAdvancedView(); | 889 UpdateAdvancedView(); |
| 907 | 890 |
| 908 return view; | 891 return view; |
| 909 } | 892 } |
| 910 | 893 |
| 911 views::Checkbox* TranslateBubbleView::GetAlwaysTranslateCheckbox() { | 894 views::Checkbox* TranslateBubbleView::GetAlwaysTranslateCheckbox() { |
| 912 if (model_->GetViewState() == TranslateBubbleModel::VIEW_STATE_ADVANCED) { | 895 if (model_->GetViewState() == TranslateBubbleModel::VIEW_STATE_ADVANCED) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 958 base::string16 label; | 941 base::string16 label; |
| 959 if (model_->IsPageTranslatedInCurrentLanguages()) | 942 if (model_->IsPageTranslatedInCurrentLanguages()) |
| 960 label = l10n_util::GetStringUTF16(IDS_DONE); | 943 label = l10n_util::GetStringUTF16(IDS_DONE); |
| 961 else | 944 else |
| 962 label = l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT); | 945 label = l10n_util::GetStringUTF16(IDS_TRANSLATE_BUBBLE_ACCEPT); |
| 963 advanced_done_button_->SetText(label); | 946 advanced_done_button_->SetText(label); |
| 964 advanced_done_button_->SizeToPreferredSize(); | 947 advanced_done_button_->SizeToPreferredSize(); |
| 965 if (advanced_view_) | 948 if (advanced_view_) |
| 966 advanced_view_->Layout(); | 949 advanced_view_->Layout(); |
| 967 } | 950 } |
| OLD | NEW |