Commit d9ef75a2 authored by groby@chromium.org's avatar groby@chromium.org

[Views, WebIntents] Enable auto-resizing for WebContents

R=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10388203

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@138297 0039d316-1c4b-4281-b951-d872f2087c98
parent 33f8ad52
...@@ -686,6 +686,7 @@ class WebIntentPickerViews : public views::ButtonListener, ...@@ -686,6 +686,7 @@ class WebIntentPickerViews : public views::ButtonListener,
virtual void SetActionString(const string16& action) OVERRIDE; virtual void SetActionString(const string16& action) OVERRIDE;
virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE; virtual void OnExtensionInstallSuccess(const std::string& id) OVERRIDE;
virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE; virtual void OnExtensionInstallFailure(const std::string& id) OVERRIDE;
virtual void OnInlineDispositionAutoResize(const gfx::Size& size) OVERRIDE;
virtual void OnInlineDispositionWebContentsLoaded( virtual void OnInlineDispositionWebContentsLoaded(
content::WebContents* web_contents) OVERRIDE; content::WebContents* web_contents) OVERRIDE;
...@@ -885,6 +886,13 @@ void WebIntentPickerViews::OnExtensionInstallFailure(const std::string& id) { ...@@ -885,6 +886,13 @@ void WebIntentPickerViews::OnExtensionInstallFailure(const std::string& id) {
// TODO(binji): What to display to user on failure? // TODO(binji): What to display to user on failure?
} }
void WebIntentPickerViews::OnInlineDispositionAutoResize(
const gfx::Size& size) {
webview_->SetPreferredSize(size);
contents_->Layout();
SizeToContents();
}
void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded( void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded(
content::WebContents* web_contents) { content::WebContents* web_contents) {
if (displaying_web_contents_) if (displaying_web_contents_)
...@@ -915,7 +923,7 @@ void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded( ...@@ -915,7 +923,7 @@ void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded(
#endif #endif
views::ColumnSet* full_cs = grid_layout->AddColumnSet(1); views::ColumnSet* full_cs = grid_layout->AddColumnSet(1);
full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 0, full_cs->AddColumn(GridLayout::FILL, GridLayout::FILL, 1.0,
GridLayout::USE_PREF, 0, 0); GridLayout::USE_PREF, 0, 0);
const WebIntentPickerModel::InstalledService* service = const WebIntentPickerModel::InstalledService* service =
...@@ -944,7 +952,7 @@ void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded( ...@@ -944,7 +952,7 @@ void WebIntentPickerViews::OnInlineDispositionWebContentsLoaded(
// Inline web contents row. // Inline web contents row.
grid_layout->StartRow(0, 1); grid_layout->StartRow(0, 1);
grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER, grid_layout->AddView(webview_, 1, 1, GridLayout::CENTER,
GridLayout::CENTER, kDialogMinWidth, 140); GridLayout::CENTER, 0, 0);
contents_->Layout(); contents_->Layout();
SizeToContents(); SizeToContents();
displaying_web_contents_ = true; displaying_web_contents_ = true;
...@@ -1148,8 +1156,7 @@ void WebIntentPickerViews::SizeToContents() { ...@@ -1148,8 +1156,7 @@ void WebIntentPickerViews::SizeToContents() {
gfx::Rect client_bounds(client_size); gfx::Rect client_bounds(client_size);
gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()-> gfx::Rect new_window_bounds = window_->non_client_view()->frame_view()->
GetWindowBoundsForClientBounds(client_bounds); GetWindowBoundsForClientBounds(client_bounds);
// TODO(binji): figure out how to get the constrained dialog centered... window_->CenterWindow(new_window_bounds.size());
window_->SetSize(new_window_bounds.size());
} }
#if defined(USE_CLOSE_BUTTON) #if defined(USE_CLOSE_BUTTON)
......
...@@ -79,6 +79,10 @@ void WebView::OnWebContentsFocused(content::WebContents* web_contents) { ...@@ -79,6 +79,10 @@ void WebView::OnWebContentsFocused(content::WebContents* web_contents) {
focus_manager->SetFocusedView(this); focus_manager->SetFocusedView(this);
} }
void WebView::SetPreferredSize(const gfx::Size& preferred_size) {
preferred_size_ = preferred_size;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WebView, View overrides: // WebView, View overrides:
...@@ -137,6 +141,13 @@ gfx::NativeViewAccessible WebView::GetNativeViewAccessible() { ...@@ -137,6 +141,13 @@ gfx::NativeViewAccessible WebView::GetNativeViewAccessible() {
return View::GetNativeViewAccessible(); return View::GetNativeViewAccessible();
} }
gfx::Size WebView::GetPreferredSize() {
if (preferred_size_ == gfx::Size())
return View::GetPreferredSize();
else
return preferred_size_;
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// WebView, content::NotificationObserver implementation: // WebView, content::NotificationObserver implementation:
......
...@@ -70,6 +70,10 @@ class VIEWS_EXPORT WebView : public View, ...@@ -70,6 +70,10 @@ class VIEWS_EXPORT WebView : public View,
allow_accelerators_ = allow_accelerators; allow_accelerators_ = allow_accelerators;
} }
// Sets the preferred size. If empty, View's implementation of
// GetPreferredSize() is used.
void SetPreferredSize(const gfx::Size& preferred_size);
// Overridden from View: // Overridden from View:
virtual std::string GetClassName() const OVERRIDE; virtual std::string GetClassName() const OVERRIDE;
...@@ -86,6 +90,7 @@ class VIEWS_EXPORT WebView : public View, ...@@ -86,6 +90,7 @@ class VIEWS_EXPORT WebView : public View,
virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE; virtual void AboutToRequestFocusFromTabTraversal(bool reverse) OVERRIDE;
virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE; virtual gfx::NativeViewAccessible GetNativeViewAccessible() OVERRIDE;
virtual gfx::Size GetPreferredSize() OVERRIDE;
// Overridden from content::NotificationObserver: // Overridden from content::NotificationObserver:
virtual void Observe(int type, virtual void Observe(int type,
...@@ -115,6 +120,7 @@ class VIEWS_EXPORT WebView : public View, ...@@ -115,6 +120,7 @@ class VIEWS_EXPORT WebView : public View,
content::BrowserContext* browser_context_; content::BrowserContext* browser_context_;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
bool allow_accelerators_; bool allow_accelerators_;
gfx::Size preferred_size_;
DISALLOW_COPY_AND_ASSIGN(WebView); DISALLOW_COPY_AND_ASSIGN(WebView);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment