Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 // Passes the event to NativeWidgetMac for handling. | |
| 17 - (void)handleUntranslatedKeyEvent:(NSEvent*)theEvent; | |
| 18 | |
| 19 // Translates the location of |theEvent| to toolkit-views coordinates and passes | |
| 20 // the event to NativeWidgetMac for handling. | |
| 21 - (void)handleMouseEvent:(NSEvent*)theEvent; | |
| 22 | |
| 23 @end | |
| 24 | |
| 25 @implementation BridgedContentView | |
| 26 | |
| 27 - (id)initWithView:(views::View*)viewToHost { | |
| 28 DCHECK(viewToHost); | |
| 29 NSRect initialFrame = ScreenRectToNSRect(viewToHost->bounds()); | |
| 30 if ((self = [super initWithFrame:initialFrame])) { | |
| 31 hostedView_ = viewToHost; | |
| 32 } | |
| 33 return self; | |
| 34 } | |
| 35 | |
| 36 - (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
| |
| 37 return hostedView_; | |
| 38 } | |
| 39 | |
| 40 - (void)clearView { | |
| 41 hostedView_ = NULL; | |
| 42 } | |
| 43 | |
| 44 // BridgedContentView private implementation. | |
| 45 | |
| 46 - (void)handleUntranslatedKeyEvent:(NSEvent*)theEvent { | |
| 47 if (!hostedView_) | |
| 48 return; | |
| 49 | |
| 50 ui::KeyEvent event(theEvent, false); | |
| 51 hostedView_->GetWidget()->OnKeyEvent(&event); | |
| 52 } | |
| 53 | |
| 54 - (void)handleMouseEvent:(NSEvent*)theEvent { | |
| 55 if (!hostedView_) | |
| 56 return; | |
| 57 | |
| 58 ui::MouseEvent event(theEvent); | |
| 59 hostedView_->GetWidget()->OnMouseEvent(&event); | |
| 60 } | |
| 61 | |
| 62 // NSView implementation. | |
| 63 | |
| 64 - (void)setFrame:(NSRect)newFrame { | |
| 65 [super setFrame:newFrame]; | |
| 66 if (!hostedView_) | |
| 67 return; | |
| 68 | |
| 69 hostedView_->SetSize(gfx::Size(NSWidth(newFrame), NSHeight(newFrame))); | |
| 70 } | |
| 71 | |
| 72 - (void)drawRect:(NSRect)dirtyRect { | |
| 73 if (!hostedView_) | |
| 74 return; | |
| 75 | |
| 76 gfx::CanvasSkiaPaint canvas(dirtyRect, false /* opaque */); | |
| 77 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
| |
| 78 } | |
| 79 | |
| 80 - (void)keyDown:(NSEvent*)theEvent { | |
| 81 [self handleUntranslatedKeyEvent:theEvent]; | |
| 82 } | |
| 83 | |
| 84 - (void)keyUp:(NSEvent*)theEvent { | |
| 85 [self handleUntranslatedKeyEvent:theEvent]; | |
| 86 } | |
| 87 | |
| 88 - (void)mouseDown:(NSEvent*)theEvent { | |
| 89 [self handleMouseEvent:theEvent]; | |
| 90 } | |
| 91 | |
| 92 - (void)mouseDragged:(NSEvent*)theEvent { | |
| 93 [self handleMouseEvent:theEvent]; | |
| 94 } | |
| 95 | |
| 96 - (void)mouseUp:(NSEvent*)theEvent { | |
| 97 [self handleMouseEvent:theEvent]; | |
| 98 } | |
| 99 | |
| 100 @end | |
| OLD | NEW |