Chromium Code Reviews| 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 <algorithm> | 5 #include <algorithm> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/command_line.h" | |
| 8 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 9 #include "base/time.h" | 10 #include "base/time.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/tab_contents/tab_util.h" | 12 #include "chrome/browser/tab_contents/tab_util.h" |
| 12 #include "chrome/browser/ui/browser_finder.h" | 13 #include "chrome/browser/ui/browser_finder.h" |
| 13 #include "chrome/browser/ui/browser_navigator.h" | 14 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" | 15 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" |
| 15 #include "chrome/browser/ui/intents/web_intent_picker.h" | 16 #include "chrome/browser/ui/intents/web_intent_picker.h" |
| 16 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" | 17 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" |
| 17 #include "chrome/browser/ui/intents/web_intent_picker_model.h" | 18 #include "chrome/browser/ui/intents/web_intent_picker_model.h" |
| 18 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" | 19 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 20 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/ui/views/constrained_window_views.h" | 21 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 21 #include "chrome/browser/ui/views/frame/browser_view.h" | 22 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 22 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" | 23 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" |
| 23 #include "chrome/browser/ui/views/toolbar_view.h" | 24 #include "chrome/browser/ui/views/toolbar_view.h" |
| 25 #include "chrome/common/chrome_switches.h" | |
| 24 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
| 25 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/browser/web_contents_view.h" | 28 #include "content/public/browser/web_contents_view.h" |
| 27 #include "grit/chromium_strings.h" | 29 #include "grit/chromium_strings.h" |
| 28 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
| 29 #include "grit/google_chrome_strings.h" | 31 #include "grit/google_chrome_strings.h" |
| 30 #include "grit/shared_resources.h" | 32 #include "grit/shared_resources.h" |
| 31 #include "grit/theme_resources.h" | 33 #include "grit/theme_resources.h" |
| 32 #include "grit/ui_resources.h" | 34 #include "grit/ui_resources.h" |
| 33 #include "ipc/ipc_message.h" | 35 #include "ipc/ipc_message.h" |
| (...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 772 // Set to true when displaying the inline disposition web contents. Used to | 774 // Set to true when displaying the inline disposition web contents. Used to |
| 773 // prevent laying out the inline disposition widgets twice. | 775 // prevent laying out the inline disposition widgets twice. |
| 774 bool displaying_web_contents_; | 776 bool displaying_web_contents_; |
| 775 | 777 |
| 776 // The text for the current action. | 778 // The text for the current action. |
| 777 string16 action_text_; | 779 string16 action_text_; |
| 778 | 780 |
| 779 // Ownership of the WebContents we are displaying in the inline disposition. | 781 // Ownership of the WebContents we are displaying in the inline disposition. |
| 780 scoped_ptr<WebContents> inline_web_contents_; | 782 scoped_ptr<WebContents> inline_web_contents_; |
| 781 | 783 |
| 784 // Indicate if dialog should display its own close button. | |
| 785 // TODO(groby): Only relevant until new ConstrainedWindow is implemented, | |
| 786 // from then on always true. | |
| 787 bool use_close_button_; | |
| 788 | |
| 782 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerViews); | 789 DISALLOW_COPY_AND_ASSIGN(WebIntentPickerViews); |
| 783 }; | 790 }; |
| 784 | 791 |
| 785 // static | 792 // static |
| 786 WebIntentPicker* WebIntentPicker::Create(TabContents* tab_contents, | 793 WebIntentPicker* WebIntentPicker::Create(TabContents* tab_contents, |
| 787 WebIntentPickerDelegate* delegate, | 794 WebIntentPickerDelegate* delegate, |
| 788 WebIntentPickerModel* model) { | 795 WebIntentPickerModel* model) { |
| 789 return new WebIntentPickerViews(tab_contents, delegate, model); | 796 return new WebIntentPickerViews(tab_contents, delegate, model); |
| 790 } | 797 } |
| 791 | 798 |
| 792 WebIntentPickerViews::WebIntentPickerViews(TabContents* tab_contents, | 799 WebIntentPickerViews::WebIntentPickerViews(TabContents* tab_contents, |
| 793 WebIntentPickerDelegate* delegate, | 800 WebIntentPickerDelegate* delegate, |
| 794 WebIntentPickerModel* model) | 801 WebIntentPickerModel* model) |
| 795 : delegate_(delegate), | 802 : delegate_(delegate), |
| 796 model_(model), | 803 model_(model), |
| 797 service_buttons_(NULL), | 804 service_buttons_(NULL), |
| 798 action_label_(NULL), | 805 action_label_(NULL), |
| 799 suggestions_label_(NULL), | 806 suggestions_label_(NULL), |
| 800 extensions_(NULL), | 807 extensions_(NULL), |
| 801 tab_contents_(tab_contents), | 808 tab_contents_(tab_contents), |
| 802 webview_(new views::WebView(tab_contents->profile())), | 809 webview_(new views::WebView(tab_contents->profile())), |
| 803 contents_(NULL), | 810 contents_(NULL), |
| 804 window_(NULL), | 811 window_(NULL), |
| 805 more_suggestions_link_(NULL), | 812 more_suggestions_link_(NULL), |
| 806 choose_another_service_link_(NULL), | 813 choose_another_service_link_(NULL), |
| 807 displaying_web_contents_(false) { | 814 displaying_web_contents_(false) { |
| 815 CommandLine* command_line = CommandLine::ForCurrentProcess(); | |
|
Peter Kasting
2012/08/14 18:20:35
Nit: Or just inline into next statement and wrap a
groby-ooo-7-16
2012/08/14 21:27:00
Done.
| |
| 816 use_close_button_ = | |
| 817 command_line->HasSwitch(switches::kEnableFramelessConstrainedDialogs); | |
| 818 | |
| 808 model_->set_observer(this); | 819 model_->set_observer(this); |
| 809 InitContents(); | 820 InitContents(); |
| 810 | 821 |
| 811 // Show the dialog. | 822 // Show the dialog. |
| 812 window_ = new ConstrainedWindowViews(tab_contents, this); | 823 window_ = new ConstrainedWindowViews(tab_contents, this); |
| 813 } | 824 } |
| 814 | 825 |
| 815 WebIntentPickerViews::~WebIntentPickerViews() { | 826 WebIntentPickerViews::~WebIntentPickerViews() { |
| 816 model_->set_observer(NULL); | 827 model_->set_observer(NULL); |
| 817 } | 828 } |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 947 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); | 958 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); |
| 948 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 959 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 949 GridLayout::USE_PREF, 0, 0); // Icon. | 960 GridLayout::USE_PREF, 0, 0); // Icon. |
| 950 header_cs->AddPaddingColumn(0, 4); | 961 header_cs->AddPaddingColumn(0, 4); |
| 951 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 962 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 952 GridLayout::USE_PREF, 0, 0); // Title. | 963 GridLayout::USE_PREF, 0, 0); // Title. |
| 953 header_cs->AddPaddingColumn(0, 4); | 964 header_cs->AddPaddingColumn(0, 4); |
| 954 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 965 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 955 GridLayout::USE_PREF, 0, 0); // Link. | 966 GridLayout::USE_PREF, 0, 0); // Link. |
| 956 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 967 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 957 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 968 if (use_close_button_) |
|
Peter Kasting
2012/08/14 18:20:35
Nit: {}
groby-ooo-7-16
2012/08/14 21:27:00
Done.
| |
| 958 GridLayout::USE_PREF, 0, 0); // Close Button. | 969 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 970 GridLayout::USE_PREF, 0, 0); // Close Button. | |
| 959 | 971 |
| 960 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); | 972 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); |
| 961 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0, | 973 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0, |
| 962 GridLayout::USE_PREF, 0, 0); | 974 GridLayout::USE_PREF, 0, 0); |
| 963 | 975 |
| 964 const WebIntentPickerModel::InstalledService* service = | 976 const WebIntentPickerModel::InstalledService* service = |
| 965 model_->GetInstalledServiceWithURL(model_->inline_disposition_url()); | 977 model_->GetInstalledServiceWithURL(model_->inline_disposition_url()); |
| 966 | 978 |
| 967 // Header row. | 979 // Header row. |
| 968 grid_layout->StartRow(0, 0); | 980 grid_layout->StartRow(0, 0); |
| 969 views::ImageView* icon = new views::ImageView(); | 981 views::ImageView* icon = new views::ImageView(); |
| 970 icon->SetImage(service->favicon.ToImageSkia()); | 982 icon->SetImage(service->favicon.ToImageSkia()); |
| 971 grid_layout->AddView(icon); | 983 grid_layout->AddView(icon); |
| 972 | 984 |
| 973 string16 elided_title = ui::ElideText( | 985 string16 elided_title = ui::ElideText( |
| 974 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); | 986 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); |
| 975 views::Label* title = new views::Label(elided_title); | 987 views::Label* title = new views::Label(elided_title); |
| 976 grid_layout->AddView(title); | 988 grid_layout->AddView(title); |
| 977 // Add link for "choose another service" if other suggestions are available | 989 // Add link for "choose another service" if other suggestions are available |
| 978 // or if more than one (the current) service is installed. | 990 // or if more than one (the current) service is installed. |
| 979 if (model_->GetInstalledServiceCount() > 1 || | 991 if (model_->GetInstalledServiceCount() > 1 || |
| 980 model_->GetSuggestedExtensionCount()) { | 992 model_->GetSuggestedExtensionCount()) { |
| 981 choose_another_service_link_ = new views::Link( | 993 choose_another_service_link_ = new views::Link( |
| 982 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE)); | 994 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE)); |
| 983 grid_layout->AddView(choose_another_service_link_); | 995 grid_layout->AddView(choose_another_service_link_); |
| 984 choose_another_service_link_->set_listener(this); | 996 choose_another_service_link_->set_listener(this); |
| 985 } | 997 } |
| 986 | 998 |
| 987 grid_layout->AddView(CreateCloseButton()); | 999 if (use_close_button_) |
| 1000 grid_layout->AddView(CreateCloseButton()); | |
| 988 | 1001 |
| 989 // Inline web contents row. | 1002 // Inline web contents row. |
| 990 grid_layout->StartRow(0, 1); | 1003 grid_layout->StartRow(0, 1); |
| 991 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, | 1004 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, |
| 992 GridLayout::CENTER, 0, 0); | 1005 GridLayout::CENTER, 0, 0); |
| 993 contents_->Layout(); | 1006 contents_->Layout(); |
| 994 SizeToContents(); | 1007 SizeToContents(); |
| 995 displaying_web_contents_ = true; | 1008 displaying_web_contents_ = true; |
| 996 } | 1009 } |
| 997 | 1010 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 views::GridLayout* grid_layout = new views::GridLayout(contents_); | 1107 views::GridLayout* grid_layout = new views::GridLayout(contents_); |
| 1095 contents_->SetLayoutManager(grid_layout); | 1108 contents_->SetLayoutManager(grid_layout); |
| 1096 | 1109 |
| 1097 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0)); | 1110 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0)); |
| 1098 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, | 1111 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, |
| 1099 kContentAreaBorder, kContentAreaBorder); | 1112 kContentAreaBorder, kContentAreaBorder); |
| 1100 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet); | 1113 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet); |
| 1101 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 1114 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 1102 GridLayout::USE_PREF, 0, 0); // Title. | 1115 GridLayout::USE_PREF, 0, 0); // Title. |
| 1103 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); | 1116 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); |
| 1104 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, | 1117 if (use_close_button_) |
|
Peter Kasting
2012/08/14 18:20:35
Nit: {}
groby-ooo-7-16
2012/08/14 21:27:00
Done.
| |
| 1105 GridLayout::USE_PREF, 0, 0); // Close Button. | 1118 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, |
| 1119 GridLayout::USE_PREF, 0, 0); // Close Button. | |
| 1106 | 1120 |
| 1107 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet); | 1121 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet); |
| 1108 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 1122 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 1109 GridLayout::USE_PREF, 0, 0); | 1123 GridLayout::USE_PREF, 0, 0); |
| 1110 | 1124 |
| 1111 views::ColumnSet* indent_cs = | 1125 views::ColumnSet* indent_cs = |
| 1112 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet); | 1126 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet); |
| 1113 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); | 1127 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); |
| 1114 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, | 1128 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, |
| 1115 GridLayout::USE_PREF, 0, 0); | 1129 GridLayout::USE_PREF, 0, 0); |
| 1116 | 1130 |
| 1117 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1118 | 1132 |
| 1119 // Header row. | 1133 // Header row. |
| 1120 grid_layout->StartRow(0, kHeaderRowColumnSet); | 1134 grid_layout->StartRow(0, kHeaderRowColumnSet); |
| 1121 action_label_ = new views::Label(); | 1135 action_label_ = new views::Label(); |
| 1122 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 1136 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 1123 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 1137 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
| 1124 grid_layout->AddView(action_label_); | 1138 grid_layout->AddView(action_label_); |
| 1125 | 1139 |
| 1126 grid_layout->AddView(CreateCloseButton()); | 1140 if (use_close_button_) |
| 1141 grid_layout->AddView(CreateCloseButton()); | |
| 1127 | 1142 |
| 1128 // Padding row. | 1143 // Padding row. |
| 1129 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 1144 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1130 | 1145 |
| 1131 // Service button row. | 1146 // Service button row. |
| 1132 grid_layout->StartRow(0, kFullWidthColumnSet); | 1147 grid_layout->StartRow(0, kFullWidthColumnSet); |
| 1133 service_buttons_ = new ServiceButtonsView(model_, this); | 1148 service_buttons_ = new ServiceButtonsView(model_, this); |
| 1134 grid_layout->AddView(service_buttons_); | 1149 grid_layout->AddView(service_buttons_); |
| 1135 | 1150 |
| 1136 // Row with app suggestions label. | 1151 // Row with app suggestions label. |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 1206 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 1192 views::ImageButton* close_button = new views::ImageButton(this); | 1207 views::ImageButton* close_button = new views::ImageButton(this); |
| 1193 close_button->SetImage(views::CustomButton::BS_NORMAL, | 1208 close_button->SetImage(views::CustomButton::BS_NORMAL, |
| 1194 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X)); | 1209 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X)); |
| 1195 close_button->SetImage(views::CustomButton::BS_HOT, | 1210 close_button->SetImage(views::CustomButton::BS_HOT, |
| 1196 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); | 1211 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); |
| 1197 close_button->SetImage(views::CustomButton::BS_PUSHED, | 1212 close_button->SetImage(views::CustomButton::BS_PUSHED, |
| 1198 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); | 1213 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); |
| 1199 return close_button; | 1214 return close_button; |
| 1200 } | 1215 } |
| OLD | NEW |