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

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

Issue 10631010: Change style of ConstrainedWindowViews. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove extra "private" Created 8 years, 5 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 | « chrome/browser/ui/views/constrained_window_views.cc ('k') | chrome/chrome_browser.gypi » ('j') | 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/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/tab_contents/tab_util.h" 11 #include "chrome/browser/tab_contents/tab_util.h"
12 #include "chrome/browser/ui/browser_navigator.h" 12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" 13 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h"
14 #include "chrome/browser/ui/intents/web_intent_picker.h" 14 #include "chrome/browser/ui/intents/web_intent_picker.h"
15 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h" 15 #include "chrome/browser/ui/intents/web_intent_picker_delegate.h"
16 #include "chrome/browser/ui/intents/web_intent_picker_model.h" 16 #include "chrome/browser/ui/intents/web_intent_picker_model.h"
17 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h" 17 #include "chrome/browser/ui/intents/web_intent_picker_model_observer.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents.h"
19 #include "chrome/browser/ui/views/constrained_window_views.h" 19 #include "chrome/browser/ui/views/constrained_window_views.h"
20 #include "chrome/browser/ui/views/frame/browser_view.h" 20 #include "chrome/browser/ui/views/frame/browser_view.h"
21 #include "chrome/browser/ui/views/location_bar/location_icon_view.h" 21 #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
22 #include "chrome/browser/ui/views/toolbar_view.h" 22 #include "chrome/browser/ui/views/toolbar_view.h"
23 #include "chrome/common/extensions/extension_constants.h" 23 #include "chrome/common/extensions/extension_constants.h"
24 #include "content/public/browser/web_contents.h" 24 #include "content/public/browser/web_contents.h"
25 #include "content/public/browser/web_contents_view.h" 25 #include "content/public/browser/web_contents_view.h"
26 #include "grit/chromium_strings.h" 26 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
28 #include "grit/google_chrome_strings.h" 28 #include "grit/google_chrome_strings.h"
29 #include "grit/shared_resources.h"
29 #include "grit/theme_resources.h" 30 #include "grit/theme_resources.h"
30 #include "grit/ui_resources.h" 31 #include "grit/ui_resources.h"
31 #include "ipc/ipc_message.h" 32 #include "ipc/ipc_message.h"
32 #include "third_party/skia/include/core/SkColor.h" 33 #include "third_party/skia/include/core/SkColor.h"
33 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
35 #include "ui/base/text/text_elider.h" 36 #include "ui/base/text/text_elider.h"
36 #include "ui/gfx/canvas.h" 37 #include "ui/gfx/canvas.h"
37 #include "ui/gfx/image/image.h" 38 #include "ui/gfx/image/image.h"
38 #include "ui/views/border.h" 39 #include "ui/views/border.h"
39 #include "ui/views/controls/button/image_button.h" 40 #include "ui/views/controls/button/image_button.h"
40 #include "ui/views/controls/button/text_button.h" 41 #include "ui/views/controls/button/text_button.h"
41 #include "ui/views/controls/image_view.h" 42 #include "ui/views/controls/image_view.h"
42 #include "ui/views/controls/label.h" 43 #include "ui/views/controls/label.h"
43 #include "ui/views/controls/link.h" 44 #include "ui/views/controls/link.h"
44 #include "ui/views/controls/link_listener.h" 45 #include "ui/views/controls/link_listener.h"
45 #include "ui/views/controls/throbber.h" 46 #include "ui/views/controls/throbber.h"
46 #include "ui/views/controls/webview/webview.h" 47 #include "ui/views/controls/webview/webview.h"
47 #include "ui/views/layout/box_layout.h" 48 #include "ui/views/layout/box_layout.h"
48 #include "ui/views/layout/fill_layout.h" 49 #include "ui/views/layout/fill_layout.h"
49 #include "ui/views/layout/grid_layout.h" 50 #include "ui/views/layout/grid_layout.h"
50 #include "ui/views/layout/layout_constants.h" 51 #include "ui/views/layout/layout_constants.h"
51 #include "ui/views/view.h" 52 #include "ui/views/view.h"
52 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
53 #include "ui/views/window/dialog_delegate.h" 54 #include "ui/views/window/dialog_delegate.h"
54 #include "ui/views/window/non_client_view.h" 55 #include "ui/views/window/non_client_view.h"
55 56
56 // TODO(binji): The current constrained dialog implementation already has a
57 // close button. Remove this define and the #if checks below when we switch to
58 // the new implementation.
59 // #define USE_CLOSE_BUTTON
60
61 using content::WebContents; 57 using content::WebContents;
62 using views::GridLayout; 58 using views::GridLayout;
63 59
64 namespace { 60 namespace {
65 61
66 // The space in pixels between the top-level groups and the dialog border. 62 // The space in pixels between the top-level groups and the dialog border.
67 const int kContentAreaBorder = 12; 63 const int kContentAreaBorder = 12;
68 64
69 // The minimum size to display the constrained dialog. 65 // The minimum size to display the constrained dialog.
70 const int kDialogMinWidth = 400; 66 const int kDialogMinWidth = 400;
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Initialize the contents of the picker. After this call, contents_ will be 709 // Initialize the contents of the picker. After this call, contents_ will be
714 // non-NULL. 710 // non-NULL.
715 void InitContents(); 711 void InitContents();
716 712
717 // Restore the contents of the picker to the initial contents. 713 // Restore the contents of the picker to the initial contents.
718 void ResetContents(); 714 void ResetContents();
719 715
720 // Resize the constrained window to the size of its contents. 716 // Resize the constrained window to the size of its contents.
721 void SizeToContents(); 717 void SizeToContents();
722 718
723 #if defined(USE_CLOSE_BUTTON)
724 // Returns a new close button. 719 // Returns a new close button.
725 views::ImageButton* CreateCloseButton(); 720 views::ImageButton* CreateCloseButton();
726 #endif
727 721
728 // A weak pointer to the WebIntentPickerDelegate to notify when the user 722 // A weak pointer to the WebIntentPickerDelegate to notify when the user
729 // chooses a service or cancels. 723 // chooses a service or cancels.
730 WebIntentPickerDelegate* delegate_; 724 WebIntentPickerDelegate* delegate_;
731 725
732 // A weak pointer to the picker model. 726 // A weak pointer to the picker model.
733 WebIntentPickerModel* model_; 727 WebIntentPickerModel* model_;
734 728
735 // A weak pointer to the service button view. 729 // A weak pointer to the service button view.
736 // Created locally, owned by Views. 730 // Created locally, owned by Views.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // Show the dialog. 810 // Show the dialog.
817 window_ = new ConstrainedWindowViews(tab_contents, this); 811 window_ = new ConstrainedWindowViews(tab_contents, this);
818 } 812 }
819 813
820 WebIntentPickerViews::~WebIntentPickerViews() { 814 WebIntentPickerViews::~WebIntentPickerViews() {
821 model_->set_observer(NULL); 815 model_->set_observer(NULL);
822 } 816 }
823 817
824 void WebIntentPickerViews::ButtonPressed(views::Button* sender, 818 void WebIntentPickerViews::ButtonPressed(views::Button* sender,
825 const views::Event& event) { 819 const views::Event& event) {
826 #if defined(USE_CLOSE_BUTTON) 820 delegate_->OnPickerClosed();
827 delegate_->OnPickerCancelled();
828 #endif
829 } 821 }
830 822
831 void WebIntentPickerViews::WindowClosing() { 823 void WebIntentPickerViews::WindowClosing() {
832 delegate_->OnClosing(); 824 delegate_->OnClosing();
833 } 825 }
834 826
835 void WebIntentPickerViews::DeleteDelegate() { 827 void WebIntentPickerViews::DeleteDelegate() {
836 delete this; 828 delete this;
837 } 829 }
838 830
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); 946 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
955 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 947 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
956 GridLayout::USE_PREF, 0, 0); // Icon. 948 GridLayout::USE_PREF, 0, 0); // Icon.
957 header_cs->AddPaddingColumn(0, 4); 949 header_cs->AddPaddingColumn(0, 4);
958 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 950 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
959 GridLayout::USE_PREF, 0, 0); // Title. 951 GridLayout::USE_PREF, 0, 0); // Title.
960 header_cs->AddPaddingColumn(0, 4); 952 header_cs->AddPaddingColumn(0, 4);
961 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 953 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
962 GridLayout::USE_PREF, 0, 0); // Link. 954 GridLayout::USE_PREF, 0, 0); // Link.
963 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 955 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
964 #if defined(USE_CLOSE_BUTTON)
965 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 956 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
966 GridLayout::USE_PREF, 0, 0); // Close Button. 957 GridLayout::USE_PREF, 0, 0); // Close Button.
967 #endif
968 958
969 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); 959 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1);
970 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0, 960 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0,
971 GridLayout::USE_PREF, 0, 0); 961 GridLayout::USE_PREF, 0, 0);
972 962
973 const WebIntentPickerModel::InstalledService* service = 963 const WebIntentPickerModel::InstalledService* service =
974 model_->GetInstalledServiceWithURL(model_->inline_disposition_url()); 964 model_->GetInstalledServiceWithURL(model_->inline_disposition_url());
975 965
976 // Header row. 966 // Header row.
977 grid_layout->StartRow(0, 0); 967 grid_layout->StartRow(0, 0);
978 views::ImageView* icon = new views::ImageView(); 968 views::ImageView* icon = new views::ImageView();
979 icon->SetImage(service->favicon.ToImageSkia()); 969 icon->SetImage(service->favicon.ToImageSkia());
980 grid_layout->AddView(icon); 970 grid_layout->AddView(icon);
981 971
982 string16 elided_title = ui::ElideText( 972 string16 elided_title = ui::ElideText(
983 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); 973 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END);
984 views::Label* title = new views::Label(elided_title); 974 views::Label* title = new views::Label(elided_title);
985 grid_layout->AddView(title); 975 grid_layout->AddView(title);
986 // Add link for "choose another service" if other suggestions are available 976 // Add link for "choose another service" if other suggestions are available
987 // or if more than one (the current) service is installed. 977 // or if more than one (the current) service is installed.
988 if (model_->GetInstalledServiceCount() > 1 || 978 if (model_->GetInstalledServiceCount() > 1 ||
989 model_->GetSuggestedExtensionCount()) { 979 model_->GetSuggestedExtensionCount()) {
990 choose_another_service_link_ = new views::Link( 980 choose_another_service_link_ = new views::Link(
991 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE)); 981 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE));
992 grid_layout->AddView(choose_another_service_link_); 982 grid_layout->AddView(choose_another_service_link_);
993 choose_another_service_link_->set_listener(this); 983 choose_another_service_link_->set_listener(this);
994 } 984 }
995 985
996 #if defined(USE_CLOSE_BUTTON)
997 grid_layout->AddView(CreateCloseButton()); 986 grid_layout->AddView(CreateCloseButton());
998 #endif
999 987
1000 // Inline web contents row. 988 // Inline web contents row.
1001 grid_layout->StartRow(0, 1); 989 grid_layout->StartRow(0, 1);
1002 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, 990 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER,
1003 GridLayout::CENTER, 0, 0); 991 GridLayout::CENTER, 0, 0);
1004 contents_->Layout(); 992 contents_->Layout();
1005 SizeToContents(); 993 SizeToContents();
1006 displaying_web_contents_ = true; 994 displaying_web_contents_ = true;
1007 } 995 }
1008 996
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 views::GridLayout* grid_layout = new views::GridLayout(contents_); 1093 views::GridLayout* grid_layout = new views::GridLayout(contents_);
1106 contents_->SetLayoutManager(grid_layout); 1094 contents_->SetLayoutManager(grid_layout);
1107 1095
1108 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0)); 1096 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0));
1109 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, 1097 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder,
1110 kContentAreaBorder, kContentAreaBorder); 1098 kContentAreaBorder, kContentAreaBorder);
1111 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet); 1099 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet);
1112 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 1100 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
1113 GridLayout::USE_PREF, 0, 0); // Title. 1101 GridLayout::USE_PREF, 0, 0); // Title.
1114 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 1102 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
1115 #if defined(USE_CLOSE_BUTTON)
1116 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 1103 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
1117 GridLayout::USE_PREF, 0, 0); // Close Button. 1104 GridLayout::USE_PREF, 0, 0); // Close Button.
1118 #endif
1119 1105
1120 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet); 1106 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet);
1121 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1107 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1122 GridLayout::USE_PREF, 0, 0); 1108 GridLayout::USE_PREF, 0, 0);
1123 1109
1124 views::ColumnSet* indent_cs = 1110 views::ColumnSet* indent_cs =
1125 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet); 1111 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet);
1126 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 1112 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
1127 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1113 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1128 GridLayout::USE_PREF, 0, 0); 1114 GridLayout::USE_PREF, 0, 0);
1129 1115
1130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1116 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1131 1117
1132 // Header row. 1118 // Header row.
1133 grid_layout->StartRow(0, kHeaderRowColumnSet); 1119 grid_layout->StartRow(0, kHeaderRowColumnSet);
1134 action_label_ = new views::Label(); 1120 action_label_ = new views::Label();
1135 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 1121 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
1136 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 1122 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
1137 grid_layout->AddView(action_label_); 1123 grid_layout->AddView(action_label_);
1138 1124
1139 #if defined(USE_CLOSE_BUTTON)
1140 grid_layout->AddView(CreateCloseButton()); 1125 grid_layout->AddView(CreateCloseButton());
1141 #endif
1142 1126
1143 // Padding row. 1127 // Padding row.
1144 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1128 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
1145 1129
1146 // Service button row. 1130 // Service button row.
1147 grid_layout->StartRow(0, kFullWidthColumnSet); 1131 grid_layout->StartRow(0, kFullWidthColumnSet);
1148 service_buttons_ = new ServiceButtonsView(model_, this); 1132 service_buttons_ = new ServiceButtonsView(model_, this);
1149 grid_layout->AddView(service_buttons_); 1133 grid_layout->AddView(service_buttons_);
1150 1134
1151 // Row with app suggestions label. 1135 // Row with app suggestions label.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 } 1180 }
1197 1181
1198 void WebIntentPickerViews::SizeToContents() { 1182 void WebIntentPickerViews::SizeToContents() {
1199 gfx::Size client_size = contents_->GetPreferredSize(); 1183 gfx::Size client_size = contents_->GetPreferredSize();
1200 gfx::Rect client_bounds(client_size); 1184 gfx::Rect client_bounds(client_size);
1201 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()-> 1185 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()->
1202 GetWindowBoundsForClientBounds(client_bounds); 1186 GetWindowBoundsForClientBounds(client_bounds);
1203 window_->CenterWindow(new_window_bounds.size()); 1187 window_->CenterWindow(new_window_bounds.size());
1204 } 1188 }
1205 1189
1206 #if defined(USE_CLOSE_BUTTON)
1207 views::ImageButton* WebIntentPickerViews::CreateCloseButton() { 1190 views::ImageButton* WebIntentPickerViews::CreateCloseButton() {
1208 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1209 views::ImageButton* close_button = new views::ImageButton(this); 1192 views::ImageButton* close_button = new views::ImageButton(this);
1210 close_button->SetImage(views::CustomButton::BS_NORMAL, 1193 close_button->SetImage(views::CustomButton::BS_NORMAL,
1211 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); 1194 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
1212 close_button->SetImage(views::CustomButton::BS_HOT, 1195 close_button->SetImage(views::CustomButton::BS_HOT,
1213 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); 1196 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1214 close_button->SetImage(views::CustomButton::BS_PUSHED, 1197 close_button->SetImage(views::CustomButton::BS_PUSHED,
1215 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); 1198 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1216 return close_button; 1199 return close_button;
1217 } 1200 }
1218 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/constrained_window_views.cc ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698