OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <QuartzCore/QuartzCore.h> | 5 #include <QuartzCore/QuartzCore.h> |
6 | 6 |
7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 7 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
8 | 8 |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "content/common/gpu/gpu_messages.h" | 37 #include "content/common/gpu/gpu_messages.h" |
38 #include "content/common/native_web_keyboard_event.h" | 38 #include "content/common/native_web_keyboard_event.h" |
39 #include "content/common/plugin_messages.h" | 39 #include "content/common/plugin_messages.h" |
40 #include "content/common/view_messages.h" | 40 #include "content/common/view_messages.h" |
41 #include "skia/ext/platform_canvas.h" | 41 #include "skia/ext/platform_canvas.h" |
42 #import "third_party/mozilla/ComplexTextInputPanel.h" | 42 #import "third_party/mozilla/ComplexTextInputPanel.h" |
43 #include "third_party/skia/include/core/SkColor.h" | 43 #include "third_party/skia/include/core/SkColor.h" |
44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact
ory.h" | 44 #include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFact
ory.h" |
45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 45 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
46 #include "ui/gfx/point.h" | 46 #include "ui/gfx/point.h" |
| 47 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
47 #include "ui/gfx/surface/io_surface_support_mac.h" | 48 #include "ui/gfx/surface/io_surface_support_mac.h" |
48 #include "webkit/glue/webaccessibility.h" | 49 #include "webkit/glue/webaccessibility.h" |
49 #include "webkit/plugins/npapi/webplugin.h" | 50 #include "webkit/plugins/npapi/webplugin.h" |
50 | 51 |
51 using WebKit::WebInputEvent; | 52 using WebKit::WebInputEvent; |
52 using WebKit::WebInputEventFactory; | 53 using WebKit::WebInputEventFactory; |
53 using WebKit::WebMouseEvent; | 54 using WebKit::WebMouseEvent; |
54 using WebKit::WebMouseWheelEvent; | 55 using WebKit::WebMouseWheelEvent; |
| 56 using WebKit::WebGestureEvent; |
55 | 57 |
56 static inline int ToWebKitModifiers(NSUInteger flags) { | 58 static inline int ToWebKitModifiers(NSUInteger flags) { |
57 int modifiers = 0; | 59 int modifiers = 0; |
58 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; | 60 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; |
59 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; | 61 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; |
60 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; | 62 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; |
61 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; | 63 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; |
62 return modifiers; | 64 return modifiers; |
63 } | 65 } |
64 | 66 |
65 // Private methods: | 67 // Private methods: |
66 @interface RenderWidgetHostViewCocoa () | 68 @interface RenderWidgetHostViewCocoa () |
67 @property(nonatomic, assign) NSRange selectedRange; | 69 @property(nonatomic, assign) NSRange selectedRange; |
68 @property(nonatomic, assign) NSRange markedRange; | 70 @property(nonatomic, assign) NSRange markedRange; |
69 | 71 |
70 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 72 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
71 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 73 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
72 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; | 74 - (void)keyEvent:(NSEvent*)theEvent wasKeyEquivalent:(BOOL)equiv; |
73 - (void)cancelChildPopups; | 75 - (void)cancelChildPopups; |
74 - (void)checkForPluginImeCancellation; | 76 - (void)checkForPluginImeCancellation; |
75 @end | 77 @end |
76 | 78 |
77 // This API was published since 10.6. Provide the declaration so it can be | 79 // This API was published since 10.6. Provide the declaration so it can be |
78 // // called below when building with the 10.5 SDK. | 80 // called below when building with the 10.5 SDK. |
79 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 | 81 #if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_5 |
80 @class NSTextInputContext; | 82 @class NSTextInputContext; |
81 @interface NSResponder (AppKitDetails) | 83 @interface NSResponder (AppKitDetails) |
82 - (NSTextInputContext *)inputContext; | 84 - (NSTextInputContext *)inputContext; |
| 85 - (void)beginGestureWithEvent:(NSEvent*)event; |
| 86 - (void)endGestureWithEvent:(NSEvent*)event; |
83 @end | 87 @end |
84 #endif | 88 #endif |
85 | 89 |
| 90 // Undocumented Lion method to get the pattern for the over-scroll area. |
| 91 @interface NSColor (LionSekretAPI) |
| 92 + (NSImage*)_linenPatternImage; |
| 93 @end |
| 94 |
| 95 // NSEvent subtype for scroll gestures events. |
| 96 static const short kIOHIDEventTypeScroll = 6; |
| 97 |
86 namespace { | 98 namespace { |
87 | 99 |
88 // Maximum number of characters we allow in a tooltip. | 100 // Maximum number of characters we allow in a tooltip. |
89 const size_t kMaxTooltipLength = 1024; | 101 const size_t kMaxTooltipLength = 1024; |
90 | 102 |
91 // TODO(suzhe): Upstream this function. | 103 // TODO(suzhe): Upstream this function. |
92 WebKit::WebColor WebColorFromNSColor(NSColor *color) { | 104 WebKit::WebColor WebColorFromNSColor(NSColor *color) { |
93 CGFloat r, g, b, a; | 105 CGFloat r, g, b, a; |
94 [color getRed:&r green:&g blue:&b alpha:&a]; | 106 [color getRed:&r green:&g blue:&b alpha:&a]; |
95 | 107 |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 [self confirmComposition]; | 1216 [self confirmComposition]; |
1205 } | 1217 } |
1206 | 1218 |
1207 const WebMouseEvent& event = | 1219 const WebMouseEvent& event = |
1208 WebInputEventFactory::mouseEvent(theEvent, self); | 1220 WebInputEventFactory::mouseEvent(theEvent, self); |
1209 | 1221 |
1210 if (renderWidgetHostView_->render_widget_host_) | 1222 if (renderWidgetHostView_->render_widget_host_) |
1211 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); | 1223 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); |
1212 } | 1224 } |
1213 | 1225 |
| 1226 - (void)beginGestureWithEvent:(NSEvent*)event { |
| 1227 if ([event subtype] == kIOHIDEventTypeScroll && |
| 1228 renderWidgetHostView_->render_widget_host_) { |
| 1229 WebGestureEvent webEvent = WebInputEventFactory::gestureEvent(event, self); |
| 1230 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent); |
| 1231 } |
| 1232 |
| 1233 // Forward the gesture event to the next responder so that the browser window |
| 1234 // controller has a chance to act on back/forward gestures. |
| 1235 [[self nextResponder] beginGestureWithEvent:event]; |
| 1236 } |
| 1237 |
| 1238 - (void)endGestureWithEvent:(NSEvent*)event { |
| 1239 if ([event subtype] == kIOHIDEventTypeScroll && |
| 1240 renderWidgetHostView_->render_widget_host_) { |
| 1241 WebGestureEvent webEvent = WebInputEventFactory::gestureEvent(event, self); |
| 1242 renderWidgetHostView_->render_widget_host_->ForwardGestureEvent(webEvent); |
| 1243 } |
| 1244 |
| 1245 // Forward the gesture event to the next responder so that the browser window |
| 1246 // controller has a chance to act on back/forward gestures. |
| 1247 [[self nextResponder] endGestureWithEvent:event]; |
| 1248 } |
| 1249 |
1214 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { | 1250 - (BOOL)performKeyEquivalent:(NSEvent*)theEvent { |
1215 // |performKeyEquivalent:| is sent to all views of a window, not only down the | 1251 // |performKeyEquivalent:| is sent to all views of a window, not only down the |
1216 // responder chain (cf. "Handling Key Equivalents" in | 1252 // responder chain (cf. "Handling Key Equivalents" in |
1217 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event
Overview/HandlingKeyEvents/HandlingKeyEvents.html | 1253 // http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Event
Overview/HandlingKeyEvents/HandlingKeyEvents.html |
1218 // ). We only want to handle key equivalents if we're first responder. | 1254 // ). We only want to handle key equivalents if we're first responder. |
1219 if ([[self window] firstResponder] != self) | 1255 if ([[self window] firstResponder] != self) |
1220 return NO; | 1256 return NO; |
1221 | 1257 |
1222 // If we return |NO| from this function, cocoa will send the key event to | 1258 // If we return |NO| from this function, cocoa will send the key event to |
1223 // the menu and only if the menu does not process the event to |keyDown:|. We | 1259 // the menu and only if the menu does not process the event to |keyDown:|. We |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 y += height; | 1595 y += height; |
1560 height = -height; | 1596 height = -height; |
1561 } | 1597 } |
1562 | 1598 |
1563 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 1599 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
1564 [[NSColor whiteColor] set]; | 1600 [[NSColor whiteColor] set]; |
1565 NSRectFill(r); | 1601 NSRectFill(r); |
1566 } | 1602 } |
1567 } | 1603 } |
1568 | 1604 |
| 1605 - (void)fillRect:(NSRect)rect withPattern:(NSImage*)patternImage { |
| 1606 if (NSIsEmptyRect(rect)) |
| 1607 return; |
| 1608 |
| 1609 NSColor* patternColor = [NSColor colorWithPatternImage:patternImage]; |
| 1610 [patternColor set]; |
| 1611 NSRectFill(rect); |
| 1612 } |
| 1613 |
| 1614 - (void)drawShadow:(NSShadow*)shadow |
| 1615 withRect:(NSRect)rect |
| 1616 clip:(NSRect)clipRect { |
| 1617 gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
| 1618 NSBezierPath* drawingPath = [NSBezierPath bezierPathWithRect:rect]; |
| 1619 [shadow set]; |
| 1620 [[NSColor blackColor] set]; |
| 1621 [[NSBezierPath bezierPathWithRect:clipRect] addClip]; |
| 1622 [drawingPath fill]; |
| 1623 } |
| 1624 |
| 1625 - (NSRect)computeVisibleContentRect { |
| 1626 const RenderWidgetHost* rwh = renderWidgetHostView_->render_widget_host_; |
| 1627 gfx::Point offset = rwh->last_scroll_offset(); |
| 1628 gfx::Size size = rwh->contents_size(); |
| 1629 NSRect contentRect = |
| 1630 NSMakeRect(-offset.x(), -offset.y(), size.width(), size.height()); |
| 1631 NSRect frameRect = [self frame]; |
| 1632 frameRect.origin = NSMakePoint(0, 0); |
| 1633 return NSIntersectionRect(frameRect, contentRect); |
| 1634 } |
| 1635 |
| 1636 - (void)fillOverScrollAreas:(NSRect)dirtyRect { |
| 1637 if (![NSColor respondsToSelector:@selector(_linenPatternImage)]) |
| 1638 return; |
| 1639 |
| 1640 NSRect visibleContentRect = [self computeVisibleContentRect]; |
| 1641 NSSize frameSize = [self frame].size; |
| 1642 bool hasHorizontalOverflow = (NSWidth(visibleContentRect) < frameSize.width); |
| 1643 bool hasVerticalOverflow = (NSHeight(visibleContentRect) < frameSize.height); |
| 1644 |
| 1645 if (!hasHorizontalOverflow && !hasVerticalOverflow) |
| 1646 return; |
| 1647 |
| 1648 NSRect xRect = NSMakeRect(0, |
| 1649 0, |
| 1650 frameSize.width - NSWidth(visibleContentRect), |
| 1651 frameSize.height); |
| 1652 NSRect yRect = NSMakeRect(0, |
| 1653 0, |
| 1654 frameSize.width, |
| 1655 frameSize.height - NSHeight(visibleContentRect)); |
| 1656 NSImage* background = [NSColor _linenPatternImage]; |
| 1657 scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
| 1658 [shadow.get() setShadowColor:[NSColor blackColor]]; |
| 1659 [shadow setShadowBlurRadius:5]; |
| 1660 |
| 1661 if (hasHorizontalOverflow) { |
| 1662 NSRect shadowRect; |
| 1663 if (visibleContentRect.origin.x > 0) { |
| 1664 shadowRect = xRect; |
| 1665 shadowRect.origin.x += NSWidth(shadowRect); |
| 1666 } else { |
| 1667 xRect.origin.x = NSWidth(visibleContentRect); |
| 1668 shadowRect = xRect; |
| 1669 shadowRect.origin.x -= 1; |
| 1670 } |
| 1671 shadowRect.size.width = 1; |
| 1672 NSRect intersectRect = NSIntersectionRect(dirtyRect, xRect); |
| 1673 [self fillRect:intersectRect withPattern:background]; |
| 1674 [self drawShadow:shadow.get() withRect:shadowRect clip:intersectRect]; |
| 1675 } |
| 1676 |
| 1677 if (hasVerticalOverflow) { |
| 1678 NSRect shadowRect = visibleContentRect; |
| 1679 if (visibleContentRect.origin.y > 0) { |
| 1680 yRect.origin.y = NSHeight(visibleContentRect); |
| 1681 shadowRect.origin.y = yRect.origin.y - 1; |
| 1682 } else { |
| 1683 shadowRect.origin.y = yRect.origin.y + NSHeight(yRect); |
| 1684 } |
| 1685 shadowRect.size.height = 1; |
| 1686 NSRect intersectRect = NSIntersectionRect(dirtyRect, yRect); |
| 1687 [self fillRect:intersectRect withPattern:background]; |
| 1688 [self drawShadow:shadow.get() withRect:shadowRect clip:intersectRect]; |
| 1689 } |
| 1690 } |
| 1691 |
1569 - (void)drawRect:(NSRect)dirtyRect { | 1692 - (void)drawRect:(NSRect)dirtyRect { |
1570 if (!renderWidgetHostView_->render_widget_host_) { | 1693 if (!renderWidgetHostView_->render_widget_host_) { |
1571 // TODO(shess): Consider using something more noticable? | 1694 // TODO(shess): Consider using something more noticable? |
1572 [[NSColor whiteColor] set]; | 1695 [[NSColor whiteColor] set]; |
1573 NSRectFill(dirtyRect); | 1696 NSRectFill(dirtyRect); |
1574 return; | 1697 return; |
1575 } | 1698 } |
1576 | 1699 |
1577 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); | 1700 const gfx::Rect damagedRect([self flipNSRectToRect:dirtyRect]); |
1578 | 1701 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 CGBitmapContextCreateImage(backingStore->cg_bitmap())); | 1757 CGBitmapContextCreateImage(backingStore->cg_bitmap())); |
1635 CGRect imageRect = bitmapRect.ToCGRect(); | 1758 CGRect imageRect = bitmapRect.ToCGRect(); |
1636 imageRect.origin.y = yOffset; | 1759 imageRect.origin.y = yOffset; |
1637 CGContextDrawImage(context, imageRect, image); | 1760 CGContextDrawImage(context, imageRect, image); |
1638 } | 1761 } |
1639 } | 1762 } |
1640 | 1763 |
1641 // Fill the remaining portion of the damagedRect with white | 1764 // Fill the remaining portion of the damagedRect with white |
1642 [self fillBottomRightRemainderOfRect:bitmapRect dirtyRect:damagedRect]; | 1765 [self fillBottomRightRemainderOfRect:bitmapRect dirtyRect:damagedRect]; |
1643 | 1766 |
| 1767 // Fill the over-scroll areas, if any, with the appropriate pattern. |
| 1768 [self fillOverScrollAreas:dirtyRect]; |
| 1769 |
1644 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { | 1770 if (!renderWidgetHostView_->whiteout_start_time_.is_null()) { |
1645 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - | 1771 base::TimeDelta whiteout_duration = base::TimeTicks::Now() - |
1646 renderWidgetHostView_->whiteout_start_time_; | 1772 renderWidgetHostView_->whiteout_start_time_; |
1647 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); | 1773 UMA_HISTOGRAM_TIMES("MPArch.RWHH_WhiteoutDuration", whiteout_duration); |
1648 | 1774 |
1649 // Reset the start time to 0 so that we start recording again the next | 1775 // Reset the start time to 0 so that we start recording again the next |
1650 // time the backing store is NULL... | 1776 // time the backing store is NULL... |
1651 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); | 1777 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks(); |
1652 } | 1778 } |
1653 if (!renderWidgetHostView_->tab_switch_paint_time_.is_null()) { | 1779 if (!renderWidgetHostView_->tab_switch_paint_time_.is_null()) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1881 RenderWidgetHost* rwh = renderWidgetHostView_->render_widget_host_; | 2007 RenderWidgetHost* rwh = renderWidgetHostView_->render_widget_host_; |
1882 rwh->Send(new ViewMsg_SetAccessibilityFocus( | 2008 rwh->Send(new ViewMsg_SetAccessibilityFocus( |
1883 rwh->routing_id(), accessibilityObjectId)); | 2009 rwh->routing_id(), accessibilityObjectId)); |
1884 } | 2010 } |
1885 } | 2011 } |
1886 | 2012 |
1887 - (void)performShowMenuAction:(BrowserAccessibilityCocoa*)accessibility { | 2013 - (void)performShowMenuAction:(BrowserAccessibilityCocoa*)accessibility { |
1888 // Performs a right click copying WebKit's | 2014 // Performs a right click copying WebKit's |
1889 // accessibilityPerformShowMenuAction. | 2015 // accessibilityPerformShowMenuAction. |
1890 NSPoint location = [self accessibilityPointInScreen:accessibility]; | 2016 NSPoint location = [self accessibilityPointInScreen:accessibility]; |
1891 NSSize size = [[accessibility size] sizeValue]; | 2017 NSSize size = [[accessibility size] sizeValue]; |
1892 location = [[self window] convertScreenToBase:location]; | 2018 location = [[self window] convertScreenToBase:location]; |
1893 location.x += size.width/2; | 2019 location.x += size.width/2; |
1894 location.y += size.height/2; | 2020 location.y += size.height/2; |
1895 | 2021 |
1896 NSEvent* fakeRightClick = [NSEvent | 2022 NSEvent* fakeRightClick = [NSEvent |
1897 mouseEventWithType:NSRightMouseDown | 2023 mouseEventWithType:NSRightMouseDown |
1898 location:location | 2024 location:location |
1899 modifierFlags:nil | 2025 modifierFlags:nil |
1900 timestamp:0 | 2026 timestamp:0 |
1901 windowNumber:[[self window] windowNumber] | 2027 windowNumber:[[self window] windowNumber] |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2627 if (!string) return NO; | 2753 if (!string) return NO; |
2628 | 2754 |
2629 // If the user is currently using an IME, confirm the IME input, | 2755 // If the user is currently using an IME, confirm the IME input, |
2630 // and then insert the text from the service, the same as TextEdit and Safari. | 2756 // and then insert the text from the service, the same as TextEdit and Safari. |
2631 [self confirmComposition]; | 2757 [self confirmComposition]; |
2632 [self insertText:string]; | 2758 [self insertText:string]; |
2633 return YES; | 2759 return YES; |
2634 } | 2760 } |
2635 | 2761 |
2636 @end | 2762 @end |
OLD | NEW |