Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(778)

Unified Diff: ui/views/cocoa/bridged_content_view.mm

Issue 309483009: Remaining bits to get views_examples_with_content_exe to work on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase to master@r275900 Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/cocoa/bridged_content_view.mm
diff --git a/ui/views/cocoa/bridged_content_view.mm b/ui/views/cocoa/bridged_content_view.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6be51fd9f5df3ad587c370c76d5a82fe0e12ee72
--- /dev/null
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -0,0 +1,100 @@
+// Copyright 2014 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 "ui/views/cocoa/bridged_content_view.h"
+
+#include "ui/gfx/mac/point_utils.h"
+#include "ui/accessibility/ax_view_state.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/canvas_paint_mac.h"
+#include "ui/views/view.h"
+#include "ui/views/widget/widget.h"
+
+@interface BridgedContentView ()
+
+// Passes the event to NativeWidgetMac for handling.
+- (void)handleUntranslatedKeyEvent:(NSEvent*)theEvent;
+
+// Translates the location of |theEvent| to toolkit-views coordinates and passes
+// the event to NativeWidgetMac for handling.
+- (void)handleMouseEvent:(NSEvent*)theEvent;
+
+@end
+
+@implementation BridgedContentView
+
+- (id)initWithView:(views::View*)viewToHost {
+ DCHECK(viewToHost);
+ NSRect initialFrame = ScreenRectToNSRect(viewToHost->bounds());
+ if ((self = [super initWithFrame:initialFrame])) {
+ hostedView_ = viewToHost;
+ }
+ return self;
+}
+
+- (views::View*)view {
Robert Sesek 2014/06/11 14:53:48 Use @synthesize instead?
tapted 2014/06/12 09:09:38 Done. (in https://codereview.chromium.org/32974300
+ return hostedView_;
+}
+
+- (void)clearView {
+ hostedView_ = NULL;
+}
+
+// BridgedContentView private implementation.
+
+- (void)handleUntranslatedKeyEvent:(NSEvent*)theEvent {
+ if (!hostedView_)
+ return;
+
+ ui::KeyEvent event(theEvent, false);
+ hostedView_->GetWidget()->OnKeyEvent(&event);
+}
+
+- (void)handleMouseEvent:(NSEvent*)theEvent {
+ if (!hostedView_)
+ return;
+
+ ui::MouseEvent event(theEvent);
+ hostedView_->GetWidget()->OnMouseEvent(&event);
+}
+
+// NSView implementation.
+
+- (void)setFrame:(NSRect)newFrame {
+ [super setFrame:newFrame];
+ if (!hostedView_)
+ return;
+
+ hostedView_->SetSize(gfx::Size(NSWidth(newFrame), NSHeight(newFrame)));
+}
+
+- (void)drawRect:(NSRect)dirtyRect {
+ if (!hostedView_)
+ return;
+
+ gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */);
+ hostedView_->Paint(&canvas, views::CullSet());
Robert Sesek 2014/06/11 14:53:48 It would be great to optimize this to use dirtyRec
tapted 2014/06/12 09:09:38 At this call site, it should be clipped by the can
+}
+
+- (void)keyDown:(NSEvent*)theEvent {
+ [self handleUntranslatedKeyEvent:theEvent];
+}
+
+- (void)keyUp:(NSEvent*)theEvent {
+ [self handleUntranslatedKeyEvent:theEvent];
+}
+
+- (void)mouseDown:(NSEvent*)theEvent {
+ [self handleMouseEvent:theEvent];
+}
+
+- (void)mouseDragged:(NSEvent*)theEvent {
+ [self handleMouseEvent:theEvent];
+}
+
+- (void)mouseUp:(NSEvent*)theEvent {
+ [self handleMouseEvent:theEvent];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698