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

Side by Side Diff: chrome/browser/ui/views/web_intent_picker_views.cc

Issue 10829305: [WebIntents, Views] Custom Close button only for new ConstrainedWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix review nits. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 use_close_button_ = CommandLine::ForCurrentProcess()->HasSwitch(
816 switches::kEnableFramelessConstrainedDialogs);
817
808 model_->set_observer(this); 818 model_->set_observer(this);
809 InitContents(); 819 InitContents();
810 820
811 // Show the dialog. 821 // Show the dialog.
812 window_ = new ConstrainedWindowViews(tab_contents, this); 822 window_ = new ConstrainedWindowViews(tab_contents, this);
813 } 823 }
814 824
815 WebIntentPickerViews::~WebIntentPickerViews() { 825 WebIntentPickerViews::~WebIntentPickerViews() {
816 model_->set_observer(NULL); 826 model_->set_observer(NULL);
817 } 827 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); 957 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
948 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 958 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
949 GridLayout::USE_PREF, 0, 0); // Icon. 959 GridLayout::USE_PREF, 0, 0); // Icon.
950 header_cs->AddPaddingColumn(0, 4); 960 header_cs->AddPaddingColumn(0, 4);
951 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 961 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
952 GridLayout::USE_PREF, 0, 0); // Title. 962 GridLayout::USE_PREF, 0, 0); // Title.
953 header_cs->AddPaddingColumn(0, 4); 963 header_cs->AddPaddingColumn(0, 4);
954 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 964 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
955 GridLayout::USE_PREF, 0, 0); // Link. 965 GridLayout::USE_PREF, 0, 0); // Link.
956 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 966 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
957 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 967 if (use_close_button_) {
958 GridLayout::USE_PREF, 0, 0); // Close Button. 968 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
969 GridLayout::USE_PREF, 0, 0); // Close Button.
970 }
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
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_) {
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.
1120 }
1106 1121
1107 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet); 1122 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet);
1108 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1123 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1109 GridLayout::USE_PREF, 0, 0); 1124 GridLayout::USE_PREF, 0, 0);
1110 1125
1111 views::ColumnSet* indent_cs = 1126 views::ColumnSet* indent_cs =
1112 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet); 1127 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet);
1113 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 1128 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
1114 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1129 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1115 GridLayout::USE_PREF, 0, 0); 1130 GridLayout::USE_PREF, 0, 0);
1116 1131
1117 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1132 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1118 1133
1119 // Header row. 1134 // Header row.
1120 grid_layout->StartRow(0, kHeaderRowColumnSet); 1135 grid_layout->StartRow(0, kHeaderRowColumnSet);
1121 action_label_ = new views::Label(); 1136 action_label_ = new views::Label();
1122 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 1137 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
1123 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 1138 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
1124 grid_layout->AddView(action_label_); 1139 grid_layout->AddView(action_label_);
1125 1140
1126 grid_layout->AddView(CreateCloseButton()); 1141 if (use_close_button_)
1142 grid_layout->AddView(CreateCloseButton());
1127 1143
1128 // Padding row. 1144 // Padding row.
1129 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1145 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
1130 1146
1131 // Service button row. 1147 // Service button row.
1132 grid_layout->StartRow(0, kFullWidthColumnSet); 1148 grid_layout->StartRow(0, kFullWidthColumnSet);
1133 service_buttons_ = new ServiceButtonsView(model_, this); 1149 service_buttons_ = new ServiceButtonsView(model_, this);
1134 grid_layout->AddView(service_buttons_); 1150 grid_layout->AddView(service_buttons_);
1135 1151
1136 // Row with app suggestions label. 1152 // Row with app suggestions label.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1207 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1192 views::ImageButton* close_button = new views::ImageButton(this); 1208 views::ImageButton* close_button = new views::ImageButton(this);
1193 close_button->SetImage(views::CustomButton::BS_NORMAL, 1209 close_button->SetImage(views::CustomButton::BS_NORMAL,
1194 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X)); 1210 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
1195 close_button->SetImage(views::CustomButton::BS_HOT, 1211 close_button->SetImage(views::CustomButton::BS_HOT,
1196 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 1212 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1197 close_button->SetImage(views::CustomButton::BS_PUSHED, 1213 close_button->SetImage(views::CustomButton::BS_PUSHED,
1198 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER)); 1214 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1199 return close_button; 1215 return close_button;
1200 } 1216 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698