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"
|
|
|
|
|
|
|
|
#include "base/scoped_ptr.h"
|
|
|
|
#include "gfx/rect.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
|
|
|
|
#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
|
|
|
|
|
|
|
|
@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));
|
|
|
|
|
|
|
|
if (browser_ && browser_->GetWebView()) {
|
|
|
|
gfx::Rect client_rect(NSRectToCGRect(rect));
|
|
|
|
// flip from cocoa coordinates
|
|
|
|
client_rect.set_y([self frame].size.height -
|
|
|
|
client_rect.height() - client_rect.y());
|
|
|
|
|
|
|
|
browser_->GetWebViewHost()->UpdatePaintRect(client_rect);
|
|
|
|
browser_->GetWebViewHost()->Paint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDown:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDown:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseUp:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseUp:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseUp:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseMoved:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDragged:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)scrollWheel:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->WheelEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)rightMouseDragged:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)otherMouseDragged:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseEntered:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseExited:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->MouseEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyDown:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->KeyEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)keyUp:(NSEvent *)theEvent {
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->KeyEvent(theEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isOpaque {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyView {
|
|
|
|
return browser_ && browser_->GetWebView();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder {
|
|
|
|
return browser_ && browser_->GetWebView();
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)becomeFirstResponder {
|
|
|
|
if (browser_ && browser_->GetWebView()) {
|
|
|
|
browser_->GetWebViewHost()->SetFocus(YES);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)resignFirstResponder {
|
|
|
|
if (browser_ && browser_->GetWebView()) {
|
|
|
|
browser_->GetWebViewHost()->SetFocus(NO);
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFrame:(NSRect)frameRect {
|
|
|
|
[super setFrame:frameRect];
|
|
|
|
if (browser_ && browser_->GetWebView())
|
|
|
|
browser_->GetWebViewHost()->Resize(gfx::Rect(NSRectToCGRect(frameRect)));
|
|
|
|
[self setNeedsDisplay:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|