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

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: Whitespace 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
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_standard.h" 31 #include "grit/ui_resources_standard.h"
32 #include "ipc/ipc_message.h" 32 #include "ipc/ipc_message.h"
33 #include "third_party/skia/include/core/SkColor.h" 33 #include "third_party/skia/include/core/SkColor.h"
34 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/resource/resource_bundle.h" 35 #include "ui/base/resource/resource_bundle.h"
36 #include "ui/base/text/text_elider.h" 36 #include "ui/base/text/text_elider.h"
37 #include "ui/gfx/canvas.h" 37 #include "ui/gfx/canvas.h"
38 #include "ui/gfx/image/image.h" 38 #include "ui/gfx/image/image.h"
39 #include "ui/views/border.h" 39 #include "ui/views/border.h"
40 #include "ui/views/controls/button/image_button.h" 40 #include "ui/views/controls/button/image_button.h"
41 #include "ui/views/controls/button/text_button.h" 41 #include "ui/views/controls/button/text_button.h"
42 #include "ui/views/controls/image_view.h" 42 #include "ui/views/controls/image_view.h"
43 #include "ui/views/controls/label.h" 43 #include "ui/views/controls/label.h"
44 #include "ui/views/controls/link.h" 44 #include "ui/views/controls/link.h"
45 #include "ui/views/controls/link_listener.h" 45 #include "ui/views/controls/link_listener.h"
46 #include "ui/views/controls/throbber.h" 46 #include "ui/views/controls/throbber.h"
47 #include "ui/views/controls/webview/webview.h" 47 #include "ui/views/controls/webview/webview.h"
48 #include "ui/views/layout/box_layout.h" 48 #include "ui/views/layout/box_layout.h"
49 #include "ui/views/layout/fill_layout.h" 49 #include "ui/views/layout/fill_layout.h"
50 #include "ui/views/layout/grid_layout.h" 50 #include "ui/views/layout/grid_layout.h"
51 #include "ui/views/layout/layout_constants.h" 51 #include "ui/views/layout/layout_constants.h"
52 #include "ui/views/view.h" 52 #include "ui/views/view.h"
53 #include "ui/views/widget/widget.h" 53 #include "ui/views/widget/widget.h"
54 #include "ui/views/window/dialog_delegate.h" 54 #include "ui/views/window/dialog_delegate.h"
55 #include "ui/views/window/non_client_view.h" 55 #include "ui/views/window/non_client_view.h"
56 56
57 // TODO(binji): The current constrained dialog implementation already has a
58 // close button. Remove this define and the #if checks below when we switch to
59 // the new implementation.
60 // #define USE_CLOSE_BUTTON
61
62 using content::WebContents; 57 using content::WebContents;
63 using views::GridLayout; 58 using views::GridLayout;
64 59
65 namespace { 60 namespace {
66 61
67 // 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.
68 const int kContentAreaBorder = 12; 63 const int kContentAreaBorder = 12;
69 64
70 // The minimum size to display the constrained dialog. 65 // The minimum size to display the constrained dialog.
71 const int kDialogMinWidth = 400; 66 const int kDialogMinWidth = 400;
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Initialize the contents of the picker. After this call, contents_ will be 708 // Initialize the contents of the picker. After this call, contents_ will be
714 // non-NULL. 709 // non-NULL.
715 void InitContents(); 710 void InitContents();
716 711
717 // Restore the contents of the picker to the initial contents. 712 // Restore the contents of the picker to the initial contents.
718 void ResetContents(); 713 void ResetContents();
719 714
720 // Resize the constrained window to the size of its contents. 715 // Resize the constrained window to the size of its contents.
721 void SizeToContents(); 716 void SizeToContents();
722 717
723 #if defined(USE_CLOSE_BUTTON)
724 // Returns a new close button. 718 // Returns a new close button.
725 views::ImageButton* CreateCloseButton(); 719 views::ImageButton* CreateCloseButton();
726 #endif
727 720
728 // A weak pointer to the WebIntentPickerDelegate to notify when the user 721 // A weak pointer to the WebIntentPickerDelegate to notify when the user
729 // chooses a service or cancels. 722 // chooses a service or cancels.
730 WebIntentPickerDelegate* delegate_; 723 WebIntentPickerDelegate* delegate_;
731 724
732 // A weak pointer to the picker model. 725 // A weak pointer to the picker model.
733 WebIntentPickerModel* model_; 726 WebIntentPickerModel* model_;
734 727
735 // A weak pointer to the service button view. 728 // A weak pointer to the service button view.
736 // Created locally, owned by Views. 729 // Created locally, owned by Views.
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 // Show the dialog. 809 // Show the dialog.
817 window_ = new ConstrainedWindowViews(tab_contents, this); 810 window_ = new ConstrainedWindowViews(tab_contents, this);
818 } 811 }
819 812
820 WebIntentPickerViews::~WebIntentPickerViews() { 813 WebIntentPickerViews::~WebIntentPickerViews() {
821 model_->set_observer(NULL); 814 model_->set_observer(NULL);
822 } 815 }
823 816
824 void WebIntentPickerViews::ButtonPressed(views::Button* sender, 817 void WebIntentPickerViews::ButtonPressed(views::Button* sender,
825 const views::Event& event) { 818 const views::Event& event) {
826 #if defined(USE_CLOSE_BUTTON) 819 delegate_->OnPickerClosed();
827 delegate_->OnPickerCancelled();
828 #endif
829 } 820 }
830 821
831 void WebIntentPickerViews::WindowClosing() { 822 void WebIntentPickerViews::WindowClosing() {
832 delegate_->OnClosing(); 823 delegate_->OnClosing();
833 } 824 }
834 825
835 void WebIntentPickerViews::DeleteDelegate() { 826 void WebIntentPickerViews::DeleteDelegate() {
836 delete this; 827 delete this;
837 } 828 }
838 829
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0); 900 views::ColumnSet* header_cs = grid_layout->AddColumnSet(0);
910 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 901 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
911 GridLayout::USE_PREF, 0, 0); // Icon. 902 GridLayout::USE_PREF, 0, 0); // Icon.
912 header_cs->AddPaddingColumn(0, 4); 903 header_cs->AddPaddingColumn(0, 4);
913 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 904 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
914 GridLayout::USE_PREF, 0, 0); // Title. 905 GridLayout::USE_PREF, 0, 0); // Title.
915 header_cs->AddPaddingColumn(0, 4); 906 header_cs->AddPaddingColumn(0, 4);
916 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 907 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
917 GridLayout::USE_PREF, 0, 0); // Link. 908 GridLayout::USE_PREF, 0, 0); // Link.
918 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 909 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
919 #if defined(USE_CLOSE_BUTTON)
920 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 910 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
921 GridLayout::USE_PREF, 0, 0); // Close Button. 911 GridLayout::USE_PREF, 0, 0); // Close Button.
922 #endif
923 912
924 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); 913 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1);
925 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0, 914 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0,
926 GridLayout::USE_PREF, 0, 0); 915 GridLayout::USE_PREF, 0, 0);
927 916
928 const WebIntentPickerModel::InstalledService* service = 917 const WebIntentPickerModel::InstalledService* service =
929 model_->GetInstalledServiceWithURL(model_->inline_disposition_url()); 918 model_->GetInstalledServiceWithURL(model_->inline_disposition_url());
930 919
931 // Header row. 920 // Header row.
932 grid_layout->StartRow(0, 0); 921 grid_layout->StartRow(0, 0);
933 views::ImageView* icon = new views::ImageView(); 922 views::ImageView* icon = new views::ImageView();
934 icon->SetImage(service->favicon.ToImageSkia()); 923 icon->SetImage(service->favicon.ToImageSkia());
935 grid_layout->AddView(icon); 924 grid_layout->AddView(icon);
936 925
937 string16 elided_title = ui::ElideText( 926 string16 elided_title = ui::ElideText(
938 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); 927 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END);
939 views::Label* title = new views::Label(elided_title); 928 views::Label* title = new views::Label(elided_title);
940 grid_layout->AddView(title); 929 grid_layout->AddView(title);
941 // Add link for "choose another service" if other suggestions are available 930 // Add link for "choose another service" if other suggestions are available
942 // or if we have more than one (the current) service installed. 931 // or if we have more than one (the current) service installed.
943 if (model_->GetInstalledServiceCount() > 1 || 932 if (model_->GetInstalledServiceCount() > 1 ||
944 model_->GetSuggestedExtensionCount()) { 933 model_->GetSuggestedExtensionCount()) {
945 choose_another_service_link_ = new views::Link( 934 choose_another_service_link_ = new views::Link(
946 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE)); 935 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE));
947 grid_layout->AddView(choose_another_service_link_); 936 grid_layout->AddView(choose_another_service_link_);
948 choose_another_service_link_->set_listener(this); 937 choose_another_service_link_->set_listener(this);
949 } 938 }
950 939
951 #if defined(USE_CLOSE_BUTTON)
952 grid_layout->AddView(CreateCloseButton()); 940 grid_layout->AddView(CreateCloseButton());
953 #endif
954 941
955 // Inline web contents row. 942 // Inline web contents row.
956 grid_layout->StartRow(0, 1); 943 grid_layout->StartRow(0, 1);
957 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, 944 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER,
958 GridLayout::CENTER, 0, 0); 945 GridLayout::CENTER, 0, 0);
959 contents_->Layout(); 946 contents_->Layout();
960 SizeToContents(); 947 SizeToContents();
961 displaying_web_contents_ = true; 948 displaying_web_contents_ = true;
962 } 949 }
963 950
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 views::GridLayout* grid_layout = new views::GridLayout(contents_); 1051 views::GridLayout* grid_layout = new views::GridLayout(contents_);
1065 contents_->SetLayoutManager(grid_layout); 1052 contents_->SetLayoutManager(grid_layout);
1066 1053
1067 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0)); 1054 grid_layout->set_minimum_size(gfx::Size(kDialogMinWidth, 0));
1068 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder, 1055 grid_layout->SetInsets(kContentAreaBorder, kContentAreaBorder,
1069 kContentAreaBorder, kContentAreaBorder); 1056 kContentAreaBorder, kContentAreaBorder);
1070 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet); 1057 views::ColumnSet* header_cs = grid_layout->AddColumnSet(kHeaderRowColumnSet);
1071 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 1058 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
1072 GridLayout::USE_PREF, 0, 0); // Title. 1059 GridLayout::USE_PREF, 0, 0); // Title.
1073 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 1060 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
1074 #if defined(USE_CLOSE_BUTTON)
1075 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 1061 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
1076 GridLayout::USE_PREF, 0, 0); // Close Button. 1062 GridLayout::USE_PREF, 0, 0); // Close Button.
1077 #endif
1078 1063
1079 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet); 1064 views::ColumnSet* full_cs = grid_layout->AddColumnSet(kFullWidthColumnSet);
1080 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1065 full_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1081 GridLayout::USE_PREF, 0, 0); 1066 GridLayout::USE_PREF, 0, 0);
1082 1067
1083 views::ColumnSet* indent_cs = 1068 views::ColumnSet* indent_cs =
1084 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet); 1069 grid_layout->AddColumnSet(kIndentedFullWidthColumnSet);
1085 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing); 1070 indent_cs->AddPaddingColumn(0, views::kUnrelatedControlHorizontalSpacing);
1086 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1, 1071 indent_cs->AddColumn(GridLayout::FILL, GridLayout::CENTER, 1,
1087 GridLayout::USE_PREF, 0, 0); 1072 GridLayout::USE_PREF, 0, 0);
1088 1073
1089 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1074 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1090 1075
1091 // Header row. 1076 // Header row.
1092 grid_layout->StartRow(0, kHeaderRowColumnSet); 1077 grid_layout->StartRow(0, kHeaderRowColumnSet);
1093 action_label_ = new views::Label(); 1078 action_label_ = new views::Label();
1094 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 1079 action_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
1095 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 1080 action_label_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
1096 grid_layout->AddView(action_label_); 1081 grid_layout->AddView(action_label_);
1097 1082
1098 #if defined(USE_CLOSE_BUTTON)
1099 grid_layout->AddView(CreateCloseButton()); 1083 grid_layout->AddView(CreateCloseButton());
1100 #endif
1101 1084
1102 // Padding row. 1085 // Padding row.
1103 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 1086 grid_layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
1104 1087
1105 // Service button row. 1088 // Service button row.
1106 grid_layout->StartRow(0, kFullWidthColumnSet); 1089 grid_layout->StartRow(0, kFullWidthColumnSet);
1107 service_buttons_ = new ServiceButtonsView(model_, this); 1090 service_buttons_ = new ServiceButtonsView(model_, this);
1108 grid_layout->AddView(service_buttons_); 1091 grid_layout->AddView(service_buttons_);
1109 1092
1110 // Row with app suggestions label. 1093 // Row with app suggestions label.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 } 1138 }
1156 1139
1157 void WebIntentPickerViews::SizeToContents() { 1140 void WebIntentPickerViews::SizeToContents() {
1158 gfx::Size client_size = contents_->GetPreferredSize(); 1141 gfx::Size client_size = contents_->GetPreferredSize();
1159 gfx::Rect client_bounds(client_size); 1142 gfx::Rect client_bounds(client_size);
1160 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()-> 1143 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()->
1161 GetWindowBoundsForClientBounds(client_bounds); 1144 GetWindowBoundsForClientBounds(client_bounds);
1162 window_->CenterWindow(new_window_bounds.size()); 1145 window_->CenterWindow(new_window_bounds.size());
1163 } 1146 }
1164 1147
1165 #if defined(USE_CLOSE_BUTTON)
1166 views::ImageButton* WebIntentPickerViews::CreateCloseButton() { 1148 views::ImageButton* WebIntentPickerViews::CreateCloseButton() {
1167 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1168 views::ImageButton* close_button = new views::ImageButton(this); 1150 views::ImageButton* close_button = new views::ImageButton(this);
1169 close_button->SetImage(views::CustomButton::BS_NORMAL, 1151 close_button->SetImage(views::CustomButton::BS_NORMAL,
1170 rb.GetImageSkiaNamed(IDR_CLOSE_BAR)); 1152 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X));
1171 close_button->SetImage(views::CustomButton::BS_HOT, 1153 close_button->SetImage(views::CustomButton::BS_HOT,
1172 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_H)); 1154 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1173 close_button->SetImage(views::CustomButton::BS_PUSHED, 1155 close_button->SetImage(views::CustomButton::BS_PUSHED,
1174 rb.GetImageSkiaNamed(IDR_CLOSE_BAR_P)); 1156 rb.GetImageSkiaNamed(IDR_SHARED_IMAGES_X_HOVER));
1175 return close_button; 1157 return close_button;
1176 } 1158 }
1177 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698