Commit 47e4e1a0 authored by avi@google.com's avatar avi@google.com

Enable child RWHVs on the Mac.

http://crbug.com/8824

Review URL: http://codereview.chromium.org/45040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12573 0039d316-1c4b-4281-b951-d872f2087c98
parent cea3dfde
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "base/task.h"
#include "base/time.h" #include "base/time.h"
#include "chrome/browser/cocoa/base_view.h" #include "chrome/browser/cocoa/base_view.h"
#include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/renderer_host/render_widget_host_view.h"
...@@ -22,8 +23,13 @@ class RenderWidgetHostViewMac; ...@@ -22,8 +23,13 @@ class RenderWidgetHostViewMac;
@interface RenderWidgetHostViewCocoa : BaseView { @interface RenderWidgetHostViewCocoa : BaseView {
@private @private
RenderWidgetHostViewMac* renderWidgetHostView_; RenderWidgetHostViewMac* renderWidgetHostView_;
BOOL canBeKeyView_;
BOOL closeOnDeactivate_;
} }
- (void)setCanBeKeyView:(BOOL)can;
- (void)setCloseOnDeactivate:(BOOL)b;
@end @end
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
...@@ -53,7 +59,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { ...@@ -53,7 +59,7 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
base::TimeTicks& whiteout_start_time() { return whiteout_start_time_; } base::TimeTicks& whiteout_start_time() { return whiteout_start_time_; }
gfx::NativeView native_view() const { return cocoa_view_; } RenderWidgetHostViewCocoa* native_view() const { return cocoa_view_; }
// Implementation of RenderWidgetHostView: // Implementation of RenderWidgetHostView:
virtual void InitAsPopup(RenderWidgetHostView* parent_host_view, virtual void InitAsPopup(RenderWidgetHostView* parent_host_view,
...@@ -82,6 +88,8 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { ...@@ -82,6 +88,8 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
virtual void SetTooltipText(const std::wstring& tooltip_text); virtual void SetTooltipText(const std::wstring& tooltip_text);
virtual BackingStore* AllocBackingStore(const gfx::Size& size); virtual BackingStore* AllocBackingStore(const gfx::Size& size);
void KillSelf();
private: private:
// Shuts down the render_widget_host_. This is a separate function so we can // Shuts down the render_widget_host_. This is a separate function so we can
// invoke it from the message loop. // invoke it from the message loop.
...@@ -109,6 +117,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView { ...@@ -109,6 +117,9 @@ class RenderWidgetHostViewMac : public RenderWidgetHostView {
// The text to be shown in the tooltip, supplied by the renderer. // The text to be shown in the tooltip, supplied by the renderer.
std::wstring tooltip_text_; std::wstring tooltip_text_;
// Factory used to safely scope delayed calls to ShutdownHost().
ScopedRunnableMethodFactory<RenderWidgetHostViewMac> shutdown_factory_;
// The time at which this view started displaying white pixels as a result of // The time at which this view started displaying white pixels as a result of
// not having anything to paint (empty backing store from renderer). This // not having anything to paint (empty backing store from renderer). This
// value returns true for is_null() if we are not recording whiteout times. // value returns true for is_null() if we are not recording whiteout times.
......
...@@ -39,7 +39,8 @@ RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( ...@@ -39,7 +39,8 @@ RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget)
: render_widget_host_(widget), : render_widget_host_(widget),
is_loading_(false), is_loading_(false),
is_hidden_(false) { is_hidden_(false),
shutdown_factory_(this) {
cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc]
initWithRenderWidgetHostViewMac:this] autorelease]; initWithRenderWidgetHostViewMac:this] autorelease];
render_widget_host_->set_view(this); render_widget_host_->set_view(this);
...@@ -54,7 +55,26 @@ RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { ...@@ -54,7 +55,26 @@ RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
void RenderWidgetHostViewMac::InitAsPopup( void RenderWidgetHostViewMac::InitAsPopup(
RenderWidgetHostView* parent_host_view, RenderWidgetHostView* parent_host_view,
const gfx::Rect& pos) { const gfx::Rect& pos) {
NOTIMPLEMENTED(); [parent_host_view->GetPluginNativeView() addSubview:cocoa_view_];
[cocoa_view_ setCloseOnDeactivate:YES];
[cocoa_view_ setCanBeKeyView:activatable_ ? YES : NO];
// TODO(avi):Why the hell are these screen coordinates? The Windows code calls
// ::MoveWindow() which indicates they should be local, but when running it I
// get global ones instead!
NSPoint global_origin = NSPointFromCGPoint(pos.origin().ToCGPoint());
global_origin.y = [[[cocoa_view_ window] screen] frame].size.height -
pos.height() - global_origin.y;
NSPoint window_origin =
[[cocoa_view_ window] convertScreenToBase:global_origin];
NSPoint view_origin =
[cocoa_view_ convertPoint:window_origin fromView:nil];
NSRect initial_frame = NSMakeRect(view_origin.x,
view_origin.y,
pos.width(),
pos.height());
[cocoa_view_ setFrame:initial_frame];
} }
RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const {
...@@ -97,9 +117,7 @@ void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { ...@@ -97,9 +117,7 @@ void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) {
} }
gfx::NativeView RenderWidgetHostViewMac::GetPluginNativeView() { gfx::NativeView RenderWidgetHostViewMac::GetPluginNativeView() {
// All plugin stuff is TBD. TODO(avi,awalker): fill in return native_view();
// http://crbug.com/8192
return nil;
} }
void RenderWidgetHostViewMac::MovePluginWindows( void RenderWidgetHostViewMac::MovePluginWindows(
...@@ -227,7 +245,17 @@ BackingStore* RenderWidgetHostViewMac::AllocBackingStore( ...@@ -227,7 +245,17 @@ BackingStore* RenderWidgetHostViewMac::AllocBackingStore(
return new BackingStore(size); return new BackingStore(size);
} }
void RenderWidgetHostViewMac::KillSelf() {
if (shutdown_factory_.empty()) {
[cocoa_view_ setHidden:YES];
MessageLoop::current()->PostTask(FROM_HERE,
shutdown_factory_.NewRunnableMethod(
&RenderWidgetHostViewMac::ShutdownHost));
}
}
void RenderWidgetHostViewMac::ShutdownHost() { void RenderWidgetHostViewMac::ShutdownHost() {
shutdown_factory_.RevokeAll();
render_widget_host_->Shutdown(); render_widget_host_->Shutdown();
// Do not touch any members at this point, |this| has been deleted. // Do not touch any members at this point, |this| has been deleted.
} }
...@@ -241,6 +269,8 @@ void RenderWidgetHostViewMac::ShutdownHost() { ...@@ -241,6 +269,8 @@ void RenderWidgetHostViewMac::ShutdownHost() {
self = [super initWithFrame:NSZeroRect]; self = [super initWithFrame:NSZeroRect];
if (self != nil) { if (self != nil) {
renderWidgetHostView_ = r; renderWidgetHostView_ = r;
canBeKeyView_ = YES;
closeOnDeactivate_ = NO;
} }
return self; return self;
} }
...@@ -251,12 +281,23 @@ void RenderWidgetHostViewMac::ShutdownHost() { ...@@ -251,12 +281,23 @@ void RenderWidgetHostViewMac::ShutdownHost() {
[super dealloc]; [super dealloc];
} }
- (void)setCanBeKeyView:(BOOL)can {
canBeKeyView_ = can;
}
- (void)setCloseOnDeactivate:(BOOL)b {
closeOnDeactivate_ = b;
}
- (void)mouseEvent:(NSEvent *)theEvent { - (void)mouseEvent:(NSEvent *)theEvent {
WebMouseEvent event(theEvent, self); WebMouseEvent event(theEvent, self);
renderWidgetHostView_->render_widget_host()->ForwardMouseEvent(event); renderWidgetHostView_->render_widget_host()->ForwardMouseEvent(event);
} }
- (void)keyEvent:(NSEvent *)theEvent { - (void)keyEvent:(NSEvent *)theEvent {
// TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and
// http://b/issue?id=1192881 .
NativeWebKeyboardEvent event(theEvent); NativeWebKeyboardEvent event(theEvent);
renderWidgetHostView_->render_widget_host()->ForwardKeyboardEvent(event); renderWidgetHostView_->render_widget_host()->ForwardKeyboardEvent(event);
} }
...@@ -339,11 +380,11 @@ void RenderWidgetHostViewMac::ShutdownHost() { ...@@ -339,11 +380,11 @@ void RenderWidgetHostViewMac::ShutdownHost() {
} }
- (BOOL)canBecomeKeyView { - (BOOL)canBecomeKeyView {
return YES; // TODO(avi): be smarter return canBeKeyView_;
} }
- (BOOL)acceptsFirstResponder { - (BOOL)acceptsFirstResponder {
return YES; // TODO(avi): be smarter return canBeKeyView_;
} }
- (BOOL)becomeFirstResponder { - (BOOL)becomeFirstResponder {
...@@ -353,6 +394,9 @@ void RenderWidgetHostViewMac::ShutdownHost() { ...@@ -353,6 +394,9 @@ void RenderWidgetHostViewMac::ShutdownHost() {
} }
- (BOOL)resignFirstResponder { - (BOOL)resignFirstResponder {
if (closeOnDeactivate_)
renderWidgetHostView_->KillSelf();
renderWidgetHostView_->render_widget_host()->Blur(); renderWidgetHostView_->render_widget_host()->Blur();
return YES; return YES;
......
...@@ -65,6 +65,10 @@ class WebContentsViewMac : public WebContentsView, ...@@ -65,6 +65,10 @@ class WebContentsViewMac : public WebContentsView,
WindowOpenDisposition disposition, WindowOpenDisposition disposition,
const gfx::Rect& initial_pos, const gfx::Rect& initial_pos,
bool user_gesture); bool user_gesture);
virtual RenderWidgetHostView* CreateNewWidgetInternal(int route_id,
bool activatable);
virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
const gfx::Rect& initial_pos);
virtual void ShowContextMenu(const ContextMenuParams& params); virtual void ShowContextMenu(const ContextMenuParams& params);
virtual void StartDragging(const WebDropData& drop_data); virtual void StartDragging(const WebDropData& drop_data);
virtual void UpdateDragCursor(bool is_drop_target); virtual void UpdateDragCursor(bool is_drop_target);
......
...@@ -217,6 +217,33 @@ void WebContentsViewMac::ShowCreatedWindowInternal( ...@@ -217,6 +217,33 @@ void WebContentsViewMac::ShowCreatedWindowInternal(
user_gesture); user_gesture);
} }
RenderWidgetHostView* WebContentsViewMac::CreateNewWidgetInternal(
int route_id,
bool activatable) {
// A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it
// to allow it to survive the trip without being hosted.
RenderWidgetHostView* widget_view =
WebContentsView::CreateNewWidgetInternal(route_id, activatable);
RenderWidgetHostViewMac* widget_view_mac =
static_cast<RenderWidgetHostViewMac*>(widget_view);
[widget_view_mac->native_view() retain];
return widget_view;
}
void WebContentsViewMac::ShowCreatedWidgetInternal(
RenderWidgetHostView* widget_host_view,
const gfx::Rect& initial_pos) {
WebContentsView::ShowCreatedWidgetInternal(widget_host_view, initial_pos);
// A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
// properly embedded (or purposefully ignored) we can release the retain we
// took in CreateNewWidgetInternal().
RenderWidgetHostViewMac* widget_view_mac =
static_cast<RenderWidgetHostViewMac*>(widget_host_view);
[widget_view_mac->native_view() release];
}
void WebContentsViewMac::Observe(NotificationType type, void WebContentsViewMac::Observe(NotificationType type,
const NotificationSource& source, const NotificationSource& source,
const NotificationDetails& details) { const NotificationDetails& details) {
......
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