diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 23:48:12 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 23:48:12 +0000 |
commit | 74aba36cbf2749781784c705fb04e2bd7716cdff (patch) | |
tree | cdc2ce51571beaa23a67f97103e0d6f3f22a6711 | |
parent | 142919371a757381b80a3358c10ee1ea50033389 (diff) | |
download | chromium_src-74aba36cbf2749781784c705fb04e2bd7716cdff.zip chromium_src-74aba36cbf2749781784c705fb04e2bd7716cdff.tar.gz chromium_src-74aba36cbf2749781784c705fb04e2bd7716cdff.tar.bz2 |
Misc. cleanup for extension_view_views.*:
* unix_hacker()-style accessors must be defined inline; inlined functions must
be named unix_hacker()-style
* Class declarations and friend statements go atop the section
* Put overrides above non-virtuals (since public and private sections disagreed,
I'm just picking one for consistency)
* Declare overrides in the same order as in the original base class header
* Inline two unnecessary temps, de-inline a repeated non-cheap call
The only functional change here is that GetMinimumSize() was moved from private
to public since I need to call that in some infobar code.
BUG=none
TEST=none
R=msw@chromium.org
Review URL: https://codereview.chromium.org/119683002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242210 0039d316-1c4b-4281-b951-d872f2087c98
4 files changed, 87 insertions, 112 deletions
diff --git a/chrome/browser/ui/views/extensions/extension_dialog.cc b/chrome/browser/ui/views/extensions/extension_dialog.cc index dc6e1de..e4f5f5c 100644 --- a/chrome/browser/ui/views/extensions/extension_dialog.cc +++ b/chrome/browser/ui/views/extensions/extension_dialog.cc @@ -63,7 +63,7 @@ ExtensionDialog* ExtensionDialog::Show( // Preferred size must be set before views::Widget::CreateWindowWithParent // is called because CreateWindowWithParent refers the result of CanResize(). host->view()->SetPreferredSize(gfx::Size(width, height)); - host->view()->SetMinimumSize(gfx::Size(min_width, min_height)); + host->view()->set_minimum_size(gfx::Size(min_width, min_height)); host->SetAssociatedWebContents(web_contents); CHECK(base_window); diff --git a/chrome/browser/ui/views/extensions/extension_popup.cc b/chrome/browser/ui/views/extensions/extension_popup.cc index 7d9a406..3afafb1 100644 --- a/chrome/browser/ui/views/extensions/extension_popup.cc +++ b/chrome/browser/ui/views/extensions/extension_popup.cc @@ -80,7 +80,7 @@ ExtensionPopup::ExtensionPopup(extensions::ExtensionViewHost* host, set_margins(gfx::Insets(margin, margin, margin, margin)); SetLayoutManager(new views::FillLayout()); AddChildView(host->view()); - host->view()->SetContainer(this); + host->view()->set_container(this); // Use OnNativeFocusChange to check for child window activation on deactivate. set_close_on_deactivate(false); // Make the bubble move with its anchor (during inspection, etc.). diff --git a/chrome/browser/ui/views/extensions/extension_view_views.cc b/chrome/browser/ui/views/extensions/extension_view_views.cc index f94a4f2..cf4ca43 100644 --- a/chrome/browser/ui/views/extensions/extension_view_views.cc +++ b/chrome/browser/ui/views/extensions/extension_view_views.cc @@ -38,28 +38,10 @@ ExtensionViewViews::~ExtensionViewViews() { CleanUp(); } -const extensions::Extension* ExtensionViewViews::extension() const { - return host_->extension(); -} - -content::RenderViewHost* ExtensionViewViews::render_view_host() const { - return host_->render_view_host(); -} - -void ExtensionViewViews::DidStopLoading() { - ShowIfCompletelyLoaded(); -} - -void ExtensionViewViews::SetIsClipped(bool is_clipped) { - if (is_clipped_ != is_clipped) { - is_clipped_ = is_clipped; - if (visible()) - ShowIfCompletelyLoaded(); - } -} - -gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) { - return gfx::kNullCursor; +gfx::Size ExtensionViewViews::GetMinimumSize() { + // If the minimum size has never been set, returns the preferred size (same + // behavior as views::View). + return (minimum_size_ == gfx::Size()) ? GetPreferredSize() : minimum_size_; } void ExtensionViewViews::SetVisible(bool is_visible) { @@ -69,51 +51,37 @@ void ExtensionViewViews::SetVisible(bool is_visible) { // Also tell RenderWidgetHostView the new visibility. Despite its name, it // is not part of the View hierarchy and does not know about the change // unless we tell it. - if (render_view_host()->GetView()) { + content::RenderWidgetHostView* host_view = render_view_host()->GetView(); + if (host_view) { if (is_visible) - render_view_host()->GetView()->Show(); + host_view->Show(); else - render_view_host()->GetView()->Hide(); + host_view->Hide(); } } } -void ExtensionViewViews::CreateWidgetHostView() { - DCHECK(!initialized_); - initialized_ = true; - Attach(host_->host_contents()->GetView()->GetNativeView()); - host_->CreateRenderViewSoon(); - SetVisible(false); -} - -void ExtensionViewViews::ShowIfCompletelyLoaded() { - if (visible() || is_clipped_) - return; - - // We wait to show the ExtensionViewViews until it has loaded, and the view - // has actually been created. These can happen in different orders. - if (host_->did_stop_loading()) { - SetVisible(true); - ResizeDueToAutoResize(pending_preferred_size_); - } +gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) { + return gfx::kNullCursor; } -void ExtensionViewViews::SetMinimumSize(const gfx::Size& size) { - minimum_size_ = size; +void ExtensionViewViews::ViewHierarchyChanged( + const ViewHierarchyChangedDetails& details) { + NativeViewHost::ViewHierarchyChanged(details); + if (details.is_add && GetWidget() && !initialized_) + CreateWidgetHostView(); } -gfx::Size ExtensionViewViews::GetMinimumSize() { - // If the minimum size has never been set, returns the preferred size (same - // behavior as views::View). - return (minimum_size_ == gfx::Size()) ? GetPreferredSize() : minimum_size_; +void ExtensionViewViews::DidStopLoading() { + ShowIfCompletelyLoaded(); } -void ExtensionViewViews::CleanUp() { - if (!initialized_) - return; - if (native_view()) - Detach(); - initialized_ = false; +void ExtensionViewViews::SetIsClipped(bool is_clipped) { + if (is_clipped_ != is_clipped) { + is_clipped_ = is_clipped; + if (visible()) + ShowIfCompletelyLoaded(); + } } void ExtensionViewViews::ResizeDueToAutoResize(const gfx::Size& new_size) { @@ -124,16 +92,23 @@ void ExtensionViewViews::ResizeDueToAutoResize(const gfx::Size& new_size) { return; } - gfx::Size preferred_size = GetPreferredSize(); - if (new_size != preferred_size) + if (new_size != GetPreferredSize()) SetPreferredSize(new_size); } -void ExtensionViewViews::ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) { - NativeViewHost::ViewHierarchyChanged(details); - if (details.is_add && GetWidget() && !initialized_) - CreateWidgetHostView(); +void ExtensionViewViews::RenderViewCreated() { + extensions::ViewType host_type = host_->extension_host_type(); + if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { + render_view_host()->EnableAutoResize( + gfx::Size(ExtensionPopup::kMinWidth, ExtensionPopup::kMinHeight), + gfx::Size(ExtensionPopup::kMaxWidth, ExtensionPopup::kMaxHeight)); + } +} + +void ExtensionViewViews::HandleKeyboardEvent( + const content::NativeWebKeyboardEvent& event) { + unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, + GetFocusManager()); } bool ExtensionViewViews::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { @@ -148,12 +123,8 @@ bool ExtensionViewViews::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { void ExtensionViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) { // Propagate the new size to RenderWidgetHostView. // We can't send size zero because RenderWidget DCHECKs that. - if (render_view_host()->GetView() && !bounds().IsEmpty()) { + if (render_view_host()->GetView() && !bounds().IsEmpty()) render_view_host()->GetView()->SetSize(size()); - - if (container_) - container_->OnViewWasResized(); - } } void ExtensionViewViews::PreferredSizeChanged() { @@ -166,22 +137,30 @@ void ExtensionViewViews::OnFocus() { host()->host_contents()->GetView()->Focus(); } -void ExtensionViewViews::RenderViewCreated() { - extensions::ViewType host_type = host_->extension_host_type(); - if (host_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { - gfx::Size min_size(ExtensionPopup::kMinWidth, - ExtensionPopup::kMinHeight); - gfx::Size max_size(ExtensionPopup::kMaxWidth, - ExtensionPopup::kMaxHeight); - render_view_host()->EnableAutoResize(min_size, max_size); - } +void ExtensionViewViews::CreateWidgetHostView() { + DCHECK(!initialized_); + initialized_ = true; + Attach(host_->host_contents()->GetView()->GetNativeView()); + host_->CreateRenderViewSoon(); + SetVisible(false); +} - if (container_) - container_->OnViewWasResized(); +void ExtensionViewViews::ShowIfCompletelyLoaded() { + if (visible() || is_clipped_) + return; + + // We wait to show the ExtensionViewViews until it has loaded, and the view + // has actually been created. These can happen in different orders. + if (host_->did_stop_loading()) { + SetVisible(true); + ResizeDueToAutoResize(pending_preferred_size_); + } } -void ExtensionViewViews::HandleKeyboardEvent( - const content::NativeWebKeyboardEvent& event) { - unhandled_keyboard_event_handler_.HandleKeyboardEvent(event, - GetFocusManager()); +void ExtensionViewViews::CleanUp() { + if (!initialized_) + return; + if (native_view()) + Detach(); + initialized_ = false; } diff --git a/chrome/browser/ui/views/extensions/extension_view_views.h b/chrome/browser/ui/views/extensions/extension_view_views.h index 8cf7b8f..fc31675 100644 --- a/chrome/browser/ui/views/extensions/extension_view_views.h +++ b/chrome/browser/ui/views/extensions/extension_view_views.h @@ -7,6 +7,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "chrome/browser/extensions/extension_host.h" #include "content/public/browser/native_web_keyboard_event.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/views/controls/native/native_view_host.h" @@ -18,36 +19,42 @@ namespace content { class RenderViewHost; } -namespace extensions { -class Extension; -class ExtensionHost; -} - // This handles the display portion of an ExtensionHost. class ExtensionViewViews : public views::NativeViewHost { public: - ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser); - virtual ~ExtensionViewViews(); - // A class that represents the container that this view is in. // (bottom shelf, side bar, etc.) class Container { public: virtual ~Container() {} + virtual void OnExtensionSizeChanged(ExtensionViewViews* view) {} - virtual void OnViewWasResized() {} }; + ExtensionViewViews(extensions::ExtensionHost* host, Browser* browser); + virtual ~ExtensionViewViews(); + + // views::NativeViewHost: + virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual void SetVisible(bool is_visible) OVERRIDE; + virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE; + virtual void ViewHierarchyChanged( + const ViewHierarchyChangedDetails& details) OVERRIDE; + extensions::ExtensionHost* host() const { return host_; } + const extensions::Extension* extension() const { return host_->extension(); } + content::RenderViewHost* render_view_host() const { + return host_->render_view_host(); + } Browser* browser() const { return browser_; } - const extensions::Extension* extension() const; - content::RenderViewHost* render_view_host() const; + void set_minimum_size(const gfx::Size& minimum_size) { + minimum_size_ = minimum_size; + } + void set_container(Container* container) { container_ = container; } + void DidStopLoading(); void SetIsClipped(bool is_clipped); - // Sets a minimum size for the native view attached to this View. - void SetMinimumSize(const gfx::Size& min_size); - // Notification from ExtensionHost. void ResizeDueToAutoResize(const gfx::Size& new_size); @@ -55,28 +62,17 @@ class ExtensionViewViews : public views::NativeViewHost { // connection. void RenderViewCreated(); - // Sets the container for this view. - void SetContainer(Container* container) { container_ = container; } - // Handles unhandled keyboard messages coming back from the renderer process. void HandleKeyboardEvent(const content::NativeWebKeyboardEvent& event); - // Overridden from views::NativeViewHost: - virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE; - virtual void SetVisible(bool is_visible) OVERRIDE; - virtual void ViewHierarchyChanged( - const ViewHierarchyChangedDetails& details) OVERRIDE; - private: - // Overridden from views::View. + friend class extensions::ExtensionHost; + + // views::NativeViewHost: virtual bool SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) OVERRIDE; virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE; virtual void PreferredSizeChanged() OVERRIDE; virtual void OnFocus() OVERRIDE; - virtual gfx::Size GetMinimumSize() OVERRIDE; - - private: - friend class extensions::ExtensionHost; // Initializes the RenderWidgetHostView for this object. void CreateWidgetHostView(); |