2010-10-23 19:00:47 +02:00
|
|
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#import "browser_webview_mac.h"
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "browser_impl.h"
|
2010-11-15 16:39:56 +01:00
|
|
|
#include "cef_context.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "webwidget_host.h"
|
|
|
|
|
2011-04-05 18:17:33 +02:00
|
|
|
#include "base/memory/scoped_ptr.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
|
#include "ui/gfx/rect.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
@implementation BrowserWebView
|
|
|
|
|
|
|
|
@synthesize browser = browser_;
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frame {
|
|
|
|
self = [super initWithFrame:frame];
|
|
|
|
if (self) {
|
|
|
|
trackingArea_ =
|
|
|
|
[[NSTrackingArea alloc] initWithRect:frame
|
|
|
|
options:NSTrackingMouseMoved |
|
|
|
|
NSTrackingActiveInActiveApp |
|
|
|
|
NSTrackingInVisibleRect
|
|
|
|
owner:self
|
|
|
|
userInfo:nil];
|
|
|
|
[self addTrackingArea:trackingArea_];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc {
|
2010-11-15 16:39:56 +01:00
|
|
|
browser_->UIT_DestroyBrowser();
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
[self removeTrackingArea:trackingArea_];
|
|
|
|
[trackingArea_ release];
|
2010-11-15 16:39:56 +01:00
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)drawRect:(NSRect)rect {
|
|
|
|
CGContextRef context =
|
|
|
|
reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext]
|
|
|
|
graphicsPort]);
|
|
|
|
|
|
|
|
// start by filling the rect with magenta, so that we can see what's drawn
|
|
|
|
CGContextSetRGBFillColor (context, 1, 0, 1, 1);
|
|
|
|
CGContextFillRect(context, NSRectToCGRect(rect));
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView()) {
|
2010-10-23 19:00:47 +02:00
|
|
|
gfx::Rect client_rect(NSRectToCGRect(rect));
|
|
|
|
// flip from cocoa coordinates
|
|
|
|
client_rect.set_y([self frame].size.height -
|
|
|
|
client_rect.height() - client_rect.y());
|
|
|
|
|
2011-01-29 02:42:59 +01:00
|
|
|
browser_->UIT_GetWebViewHost()->UpdatePaintRect(client_rect);
|
|
|
|
browser_->UIT_GetWebViewHost()->Paint();
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->WheelEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->MouseEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)theEvent {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->KeyEvent(theEvent);
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isOpaque {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyView {
|
2011-01-29 02:42:59 +01:00
|
|
|
return browser_ && browser_->UIT_GetWebView();
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder {
|
2011-01-29 02:42:59 +01:00
|
|
|
return browser_ && browser_->UIT_GetWebView();
|
2010-10-23 19:00:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)becomeFirstResponder {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView()) {
|
|
|
|
browser_->UIT_GetWebViewHost()->SetFocus(YES);
|
2010-10-23 19:00:47 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)resignFirstResponder {
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView()) {
|
|
|
|
browser_->UIT_GetWebViewHost()->SetFocus(NO);
|
2010-10-23 19:00:47 +02:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFrame:(NSRect)frameRect {
|
|
|
|
[super setFrame:frameRect];
|
2011-01-29 02:42:59 +01:00
|
|
|
if (browser_ && browser_->UIT_GetWebView())
|
|
|
|
browser_->UIT_GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect)));
|
2010-10-23 19:00:47 +02:00
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|