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

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

Issue 10388203: [Views, WebIntents] Enable auto-resizing for WebContents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Actually made resize work Created 8 years, 7 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
« no previous file with comments | « no previous file | ui/views/controls/webview/webview.h » ('j') | ui/views/controls/webview/webview.h » ('J')
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 "chrome/browser/tab_contents/tab_util.h" 10 #include "chrome/browser/tab_contents/tab_util.h"
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 virtual int GetDialogButtons() const OVERRIDE; 679 virtual int GetDialogButtons() const OVERRIDE;
680 680
681 // LinkListener implementation. 681 // LinkListener implementation.
682 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; 682 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
683 683
684 // WebIntentPicker implementation. 684 // WebIntentPicker implementation.
685 virtual void Close() OVERRIDE; 685 virtual void Close() OVERRIDE;
686 virtual void SetActionString(const string16& action) OVERRIDE; 686 virtual void SetActionString(const string16& action) OVERRIDE;
687 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; 687 virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
688 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; 688 virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
689 virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;
689 virtual void OnInlineDispositionWebContentsLoaded( 690 virtual void OnInlineDispositionWebContentsLoaded(
690 content::WebContents* web_contents) OVERRIDE; 691 content::WebContents* web_contents) OVERRIDE;
691 692
692 // WebIntentPickerModelObserver implementation. 693 // WebIntentPickerModelObserver implementation.
693 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE; 694 virtual void OnModelChanged(WebIntentPickerModel* model) OVERRIDE;
694 virtual void OnFaviconChanged(WebIntentPickerModel* model, 695 virtual void OnFaviconChanged(WebIntentPickerModel* model,
695 size_t index) OVERRIDE; 696 size_t index) OVERRIDE;
696 virtual void OnExtensionIconChanged(WebIntentPickerModel* model, 697 virtual void OnExtensionIconChanged(WebIntentPickerModel* model,
697 const string16& extension_id) OVERRIDE; 698 const string16& extension_id) OVERRIDE;
698 virtual void OnInlineDisposition(WebIntentPickerModel* model, 699 virtual void OnInlineDisposition(WebIntentPickerModel* model,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 879
879 void WebIntentPickerViews::OnExtensionInstallFailure(const std::string& id) { 880 void WebIntentPickerViews::OnExtensionInstallFailure(const std::string& id) {
880 service_buttons_->SetEnabled(true); 881 service_buttons_->SetEnabled(true);
881 extensions_->StopThrobber(); 882 extensions_->StopThrobber();
882 more_suggestions_link_->SetEnabled(true); 883 more_suggestions_link_->SetEnabled(true);
883 contents_->Layout(); 884 contents_->Layout();
884 885
885 // TODO(binji): What to display to user on failure? 886 // TODO(binji): What to display to user on failure?
886 } 887 }
887 888
889 void WebIntentPickerViews::OnInlineDispositionAutoResize(
890 const gfx::Size& size) {
891 webview_->SetPreferredSize(size);
892 contents_->Layout();
893 SizeToContents();
894 }
895
888 void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded( 896 void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded(
889 content::WebContents* web_contents) { 897 content::WebContents* web_contents) {
890 if (displaying_web_contents_) 898 if (displaying_web_contents_)
891 return; 899 return;
892 900
893 // Replace the picker with the inline disposition. 901 // Replace the picker with the inline disposition.
894 contents_->RemoveAllChildViews(true); 902 contents_->RemoveAllChildViews(true);
895 more_suggestions_link_ = NULL; 903 more_suggestions_link_ = NULL;
896 904
897 views::GridLayout* grid_layout = new views::GridLayout(contents_); 905 views::GridLayout* grid_layout = new views::GridLayout(contents_);
(...skipping 10 matching lines...) Expand all
908 header_cs->AddPaddingColumn(0, 4); 916 header_cs->AddPaddingColumn(0, 4);
909 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 917 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
910 GridLayout::USE_PREF, 0, 0); // Link. 918 GridLayout::USE_PREF, 0, 0); // Link.
911 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing); 919 header_cs->AddPaddingColumn(1, views::kUnrelatedControlHorizontalSpacing);
912 #if defined(USE_CLOSE_BUTTON) 920 #if defined(USE_CLOSE_BUTTON)
913 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0, 921 header_cs->AddColumn(GridLayout::CENTER, GridLayout::CENTER, 0,
914 GridLayout::USE_PREF, 0, 0); // Close Button. 922 GridLayout::USE_PREF, 0, 0); // Close Button.
915 #endif 923 #endif
916 924
917 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); 925 views::ColumnSet* full_cs = grid_layout->AddColumnSet(1);
918 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, 926 full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0,
919 GridLayout::USE_PREF, 0, 0); 927 GridLayout::USE_PREF, 0, 0);
920 928
921 const WebIntentPickerModel::InstalledService* service = 929 const WebIntentPickerModel::InstalledService* service =
922 model_->GetInstalledServiceWithURL(model_->inline_disposition_url()); 930 model_->GetInstalledServiceWithURL(model_->inline_disposition_url());
923 931
924 // Header row. 932 // Header row.
925 grid_layout->StartRow(0, 0); 933 grid_layout->StartRow(0, 0);
926 views::ImageView* icon = new views::ImageView(); 934 views::ImageView* icon = new views::ImageView();
927 icon->SetImage(service->favicon.ToSkBitmap()); 935 icon->SetImage(service->favicon.ToSkBitmap());
928 grid_layout->AddView(icon); 936 grid_layout->AddView(icon);
929 937
930 string16 elided_title = ui::ElideText( 938 string16 elided_title = ui::ElideText(
931 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END); 939 service->title, gfx::Font(), kTitleLinkMaxWidth, ui::ELIDE_AT_END);
932 views::Label* title = new views::Label(elided_title); 940 views::Label* title = new views::Label(elided_title);
933 grid_layout->AddView(title); 941 grid_layout->AddView(title);
934 942
935 choose_another_service_link_ = new views::Link( 943 choose_another_service_link_ = new views::Link(
936 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE)); 944 l10n_util::GetStringUTF16(IDS_INTENT_PICKER_USE_ALTERNATE_SERVICE));
937 grid_layout->AddView(choose_another_service_link_); 945 grid_layout->AddView(choose_another_service_link_);
938 choose_another_service_link_->set_listener(this); 946 choose_another_service_link_->set_listener(this);
939 947
940 #if defined(USE_CLOSE_BUTTON) 948 #if defined(USE_CLOSE_BUTTON)
941 grid_layout->AddView(CreateCloseButton()); 949 grid_layout->AddView(CreateCloseButton());
942 #endif 950 #endif
943 951
944 // Inline web contents row. 952 // Inline web contents row.
945 grid_layout->StartRow(0, 1); 953 grid_layout->StartRow(0, 1);
946 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, 954 grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER,
947 GridLayout::CENTER, kDialogMinWidth, 140); 955 GridLayout::CENTER, 0, 0);
948 contents_->Layout(); 956 contents_->Layout();
949 SizeToContents(); 957 SizeToContents();
950 displaying_web_contents_ = true; 958 displaying_web_contents_ = true;
951 } 959 }
952 960
953 void WebIntentPickerViews::OnModelChanged(WebIntentPickerModel* model) { 961 void WebIntentPickerViews::OnModelChanged(WebIntentPickerModel* model) {
954 suggestions_label_->SetText(l10n_util::GetStringUTF16( 962 suggestions_label_->SetText(l10n_util::GetStringUTF16(
955 model->GetInstalledServiceCount() ? 963 model->GetInstalledServiceCount() ?
956 IDS_INTENT_PICKER_GET_MORE_SERVICES : 964 IDS_INTENT_PICKER_GET_MORE_SERVICES :
957 IDS_INTENT_PICKER_GET_MORE_SERVICES_NONE_INSTALLED)); 965 IDS_INTENT_PICKER_GET_MORE_SERVICES_NONE_INSTALLED));
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 contents_->Layout(); 1149 contents_->Layout();
1142 SizeToContents(); 1150 SizeToContents();
1143 1151
1144 } 1152 }
1145 1153
1146 void WebIntentPickerViews::SizeToContents() { 1154 void WebIntentPickerViews::SizeToContents() {
1147 gfx::Size client_size = contents_->GetPreferredSize(); 1155 gfx::Size client_size = contents_->GetPreferredSize();
1148 gfx::Rect client_bounds(client_size); 1156 gfx::Rect client_bounds(client_size);
1149 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()-> 1157 gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()->
1150 GetWindowBoundsForClientBounds(client_bounds); 1158 GetWindowBoundsForClientBounds(client_bounds);
1151 // TODO(binji): figure out how to get the constrained dialog centered... 1159 window_->CenterWindow(new_window_bounds.size());
1152 window_->SetSize(new_window_bounds.size());
1153 } 1160 }
1154 1161
1155 #if defined(USE_CLOSE_BUTTON) 1162 #if defined(USE_CLOSE_BUTTON)
1156 views::ImageButton* WebIntentPickerViews::CreateCloseButton() { 1163 views::ImageButton* WebIntentPickerViews::CreateCloseButton() {
1157 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1164 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1158 views::ImageButton* close_button = new views::ImageButton(this); 1165 views::ImageButton* close_button = new views::ImageButton(this);
1159 close_button->SetImage(views::CustomButton::BS_NORMAL, 1166 close_button->SetImage(views::CustomButton::BS_NORMAL,
1160 rb.GetBitmapNamed(IDR_CLOSE_BAR)); 1167 rb.GetBitmapNamed(IDR_CLOSE_BAR));
1161 close_button->SetImage(views::CustomButton::BS_HOT, 1168 close_button->SetImage(views::CustomButton::BS_HOT,
1162 rb.GetBitmapNamed(IDR_CLOSE_BAR_H)); 1169 rb.GetBitmapNamed(IDR_CLOSE_BAR_H));
1163 close_button->SetImage(views::CustomButton::BS_PUSHED, 1170 close_button->SetImage(views::CustomButton::BS_PUSHED,
1164 rb.GetBitmapNamed(IDR_CLOSE_BAR_P)); 1171 rb.GetBitmapNamed(IDR_CLOSE_BAR_P));
1165 return close_button; 1172 return close_button;
1166 } 1173 }
1167 #endif 1174 #endif
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/webview/webview.h » ('j') | ui/views/controls/webview/webview.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698