| 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 "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.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" |
| 11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
| 12 #include "base/mac/scoped_cftyperef.h" | 12 #include "base/mac/scoped_cftyperef.h" |
| 13 #import "base/mac/scoped_nsautorelease_pool.h" | 13 #import "base/mac/scoped_nsautorelease_pool.h" |
| 14 #import "base/memory/scoped_nsobject.h" | 14 #import "base/memory/scoped_nsobject.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/sys_info.h" | 17 #include "base/sys_info.h" |
| 18 #include "base/sys_string_conversions.h" | 18 #include "base/sys_string_conversions.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #import "chrome/browser/ui/cocoa/color_utils.h" |
| 20 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 21 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 21 #include "content/browser/gpu/gpu_process_host.h" | 22 #include "content/browser/gpu/gpu_process_host.h" |
| 22 #include "content/browser/gpu/gpu_process_host_ui_shim.h" | 23 #include "content/browser/gpu/gpu_process_host_ui_shim.h" |
| 23 #include "content/browser/mac/closure_blocks_leopard_compat.h" | 24 #include "content/browser/mac/closure_blocks_leopard_compat.h" |
| 24 #include "content/browser/plugin_process_host.h" | 25 #include "content/browser/plugin_process_host.h" |
| 25 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" | 26 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" |
| 26 #include "content/browser/renderer_host/backing_store_mac.h" | 27 #include "content/browser/renderer_host/backing_store_mac.h" |
| 27 #include "content/browser/renderer_host/render_process_host.h" | 28 #include "content/browser/renderer_host/render_process_host.h" |
| 28 #include "content/browser/renderer_host/render_view_host.h" | 29 #include "content/browser/renderer_host/render_view_host.h" |
| 29 #import "content/browser/renderer_host/render_widget_host_view_mac_delegate.h" | 30 #import "content/browser/renderer_host/render_widget_host_view_mac_delegate.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 @end | 113 @end |
| 113 | 114 |
| 114 // NSEvent subtype for scroll gestures events. | 115 // NSEvent subtype for scroll gestures events. |
| 115 static const short kIOHIDEventTypeScroll = 6; | 116 static const short kIOHIDEventTypeScroll = 6; |
| 116 | 117 |
| 117 namespace { | 118 namespace { |
| 118 | 119 |
| 119 // Maximum number of characters we allow in a tooltip. | 120 // Maximum number of characters we allow in a tooltip. |
| 120 const size_t kMaxTooltipLength = 1024; | 121 const size_t kMaxTooltipLength = 1024; |
| 121 | 122 |
| 122 // TODO(suzhe): Upstream this function. | |
| 123 WebKit::WebColor WebColorFromNSColor(NSColor *color) { | |
| 124 CGFloat r, g, b, a; | |
| 125 [color getRed:&r green:&g blue:&b alpha:&a]; | |
| 126 | |
| 127 return | |
| 128 std::max(0, std::min(static_cast<int>(lroundf(255.0f * a)), 255)) << 24 | | |
| 129 std::max(0, std::min(static_cast<int>(lroundf(255.0f * r)), 255)) << 16 | | |
| 130 std::max(0, std::min(static_cast<int>(lroundf(255.0f * g)), 255)) << 8 | | |
| 131 std::max(0, std::min(static_cast<int>(lroundf(255.0f * b)), 255)); | |
| 132 } | |
| 133 | |
| 134 // Extract underline information from an attributed string. Mostly copied from | 123 // Extract underline information from an attributed string. Mostly copied from |
| 135 // third_party/WebKit/Source/WebKit/mac/WebView/WebHTMLView.mm | 124 // third_party/WebKit/Source/WebKit/mac/WebView/WebHTMLView.mm |
| 136 void ExtractUnderlines( | 125 void ExtractUnderlines( |
| 137 NSAttributedString* string, | 126 NSAttributedString* string, |
| 138 std::vector<WebKit::WebCompositionUnderline>* underlines) { | 127 std::vector<WebKit::WebCompositionUnderline>* underlines) { |
| 139 int length = [[string string] length]; | 128 int length = [[string string] length]; |
| 140 int i = 0; | 129 int i = 0; |
| 141 while (i < length) { | 130 while (i < length) { |
| 142 NSRange range; | 131 NSRange range; |
| 143 NSDictionary* attrs = [string attributesAtIndex:i | 132 NSDictionary* attrs = [string attributesAtIndex:i |
| (...skipping 2603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2747 if (!string) return NO; | 2736 if (!string) return NO; |
| 2748 | 2737 |
| 2749 // If the user is currently using an IME, confirm the IME input, | 2738 // If the user is currently using an IME, confirm the IME input, |
| 2750 // and then insert the text from the service, the same as TextEdit and Safari. | 2739 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2751 [self confirmComposition]; | 2740 [self confirmComposition]; |
| 2752 [self insertText:string]; | 2741 [self insertText:string]; |
| 2753 return YES; | 2742 return YES; |
| 2754 } | 2743 } |
| 2755 | 2744 |
| 2756 @end | 2745 @end |
| OLD | NEW |