This source file includes following definitions.
- is_clipped_
- GetMinimumSize
- SetVisible
- GetCursor
- ViewHierarchyChanged
- DidStopLoading
- SetIsClipped
- ResizeDueToAutoResize
- RenderViewCreated
- HandleKeyboardEvent
- SkipDefaultKeyEventProcessing
- OnBoundsChanged
- PreferredSizeChanged
- OnFocus
- CreateWidgetHostView
- ShowIfCompletelyLoaded
- CleanUp
#include "chrome/browser/ui/views/extensions/extension_view_views.h"
#include "chrome/browser/ui/views/extensions/extension_popup.h"
#include "content/public/browser/content_browser_client.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_view.h"
#include "extensions/browser/extension_host.h"
#include "extensions/common/view_type.h"
#include "ui/events/event.h"
#include "ui/views/widget/widget.h"
#if defined(USE_AURA)
#include "ui/base/cursor/cursor.h"
#endif
ExtensionViewViews::ExtensionViewViews(extensions::ExtensionHost* host,
Browser* browser)
: host_(host),
browser_(browser),
initialized_(false),
container_(NULL),
is_clipped_(false) {
SetFocusable(true);
}
ExtensionViewViews::~ExtensionViewViews() {
if (parent())
parent()->RemoveChildView(this);
CleanUp();
}
gfx::Size ExtensionViewViews::GetMinimumSize() {
return (minimum_size_ == gfx::Size()) ? GetPreferredSize() : minimum_size_;
}
void ExtensionViewViews::SetVisible(bool is_visible) {
if (is_visible != visible()) {
NativeViewHost::SetVisible(is_visible);
content::RenderWidgetHostView* host_view = render_view_host()->GetView();
if (host_view) {
if (is_visible)
host_view->Show();
else
host_view->Hide();
}
}
}
gfx::NativeCursor ExtensionViewViews::GetCursor(const ui::MouseEvent& event) {
return gfx::kNullCursor;
}
void ExtensionViewViews::ViewHierarchyChanged(
const ViewHierarchyChangedDetails& details) {
NativeViewHost::ViewHierarchyChanged(details);
if (details.is_add && GetWidget() && !initialized_)
CreateWidgetHostView();
}
void ExtensionViewViews::DidStopLoading() {
ShowIfCompletelyLoaded();
}
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) {
if (!visible()) {
pending_preferred_size_ = new_size;
return;
}
if (new_size != GetPreferredSize())
SetPreferredSize(new_size);
}
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) {
return (e.key_code() == ui::VKEY_TAB || e.key_code() == ui::VKEY_BACK);
}
void ExtensionViewViews::OnBoundsChanged(const gfx::Rect& previous_bounds) {
if (render_view_host()->GetView() && !bounds().IsEmpty())
render_view_host()->GetView()->SetSize(size());
}
void ExtensionViewViews::PreferredSizeChanged() {
View::PreferredSizeChanged();
if (container_)
container_->OnExtensionSizeChanged(this);
}
void ExtensionViewViews::OnFocus() {
host()->host_contents()->GetView()->Focus();
}
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;
if (host_->did_stop_loading()) {
SetVisible(true);
ResizeDueToAutoResize(pending_preferred_size_);
}
}
void ExtensionViewViews::CleanUp() {
if (!initialized_)
return;
if (native_view())
Detach();
initialized_ = false;
}