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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ui/views/cocoa/bridged_content_view.h"
6
7 #include "ui/gfx/mac/point_utils.h"
8 #include "ui/accessibility/ax_view_state.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/canvas_paint_mac.h"
11 #include "ui/views/view.h"
12 #include "ui/views/widget/widget.h"
13
14 @interface BridgedContentView ()
15
16 // Translates the location of |theEvent| to toolkit-views coordinates and passes
17 // the event to NativeWidgetMac for handling.
18 - (void)handleMouseEvent:(NSEvent*)theEvent;
19
20 @end
21
22 @implementation BridgedContentView
23
24 - (id)initWithView:(views::View*)viewToHost {
25 DCHECK(viewToHost);
26 NSRect initialFrame = ScreenRectToNSRect(viewToHost->bounds());
27 if ((self = [super initWithFrame:initialFrame])) {
28 hostedView_ = viewToHost;
29 }
30 return self;
31 }
32
33 - (views::View*)view {
34 return hostedView_;
35 }
36
37 - (void)clearView {
38 hostedView_ = NULL;
39 }
40
41 // BridgedContentView private implementation.
42
43 - (void)handleMouseEvent:(NSEvent*)theEvent {
44 if (!hostedView_)
45 return;
46
47 ui::MouseEvent event(theEvent);
48 hostedView_->GetWidget()->OnMouseEvent(&event);
49 }
50
51 // NSView implementation.
52
53 - (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.
54 [super setFrame:newFrame];
55 if (!hostedView_)
56 return;
57
58 hostedView_->SetSize(gfx::Size(NSWidth(newFrame), NSHeight(newFrame)));
59 }
60
61 - (void)drawRect:(NSRect)dirtyRect {
62 if (!hostedView_)
63 return;
64
65 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */);
66 hostedView_->Paint(&canvas, views::CullSet());
67 }
68
69 - (void)mouseDown:(NSEvent*)theEvent {
70 [self handleMouseEvent:theEvent];
71 }
72
73 - (void)mouseDragged:(NSEvent*)theEvent {
74 [self handleMouseEvent:theEvent];
75 }
76
77 - (void)mouseUp:(NSEvent*)theEvent {
78 [self handleMouseEvent:theEvent];
79 }
80
81 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698