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

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: neater still 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..e23c693d0423d5a137e8084af477bf072efae7c0
--- /dev/null
+++ b/ui/views/cocoa/bridged_content_view.mm
@@ -0,0 +1,81 @@
+// 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 ()
+
+// 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 {
+ return hostedView_;
+}
+
+- (void)clearView {
+ hostedView_ = NULL;
+}
+
+// BridgedContentView private implementation.
+
+- (void)handleMouseEvent:(NSEvent*)theEvent {
+ if (!hostedView_)
+ return;
+
+ ui::MouseEvent event(theEvent);
+ hostedView_->GetWidget()->OnMouseEvent(&event);
+}
+
+// NSView implementation.
+
+- (void)setFrame:(NSRect)newFrame {
Andre 2014/06/04 23:55:08 Probably better to override the more primitive -se
tapted 2014/06/11 07:38:00 Done.
+ [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());
+}
+
+- (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