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

Side by Side Diff: content/renderer/pepper/pepper_plugin_instance_impl.cc

Issue 1609193002: [UseZoomForDSF] Alwatys use DIP coordinates in pepper plugin (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 10 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/renderer/pepper/pepper_plugin_instance_impl.h" 5 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bit_cast.h" 10 #include "base/bit_cast.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 #include "ppapi/shared_impl/scoped_pp_resource.h" 88 #include "ppapi/shared_impl/scoped_pp_resource.h"
89 #include "ppapi/shared_impl/scoped_pp_var.h" 89 #include "ppapi/shared_impl/scoped_pp_var.h"
90 #include "ppapi/shared_impl/time_conversion.h" 90 #include "ppapi/shared_impl/time_conversion.h"
91 #include "ppapi/shared_impl/url_request_info_data.h" 91 #include "ppapi/shared_impl/url_request_info_data.h"
92 #include "ppapi/shared_impl/var.h" 92 #include "ppapi/shared_impl/var.h"
93 #include "ppapi/thunk/enter.h" 93 #include "ppapi/thunk/enter.h"
94 #include "ppapi/thunk/ppb_buffer_api.h" 94 #include "ppapi/thunk/ppb_buffer_api.h"
95 #include "skia/ext/platform_canvas.h" 95 #include "skia/ext/platform_canvas.h"
96 #include "third_party/WebKit/public/platform/URLConversion.h" 96 #include "third_party/WebKit/public/platform/URLConversion.h"
97 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 97 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
98 #include "third_party/WebKit/public/platform/WebFloatRect.h"
98 #include "third_party/WebKit/public/platform/WebGamepads.h" 99 #include "third_party/WebKit/public/platform/WebGamepads.h"
99 #include "third_party/WebKit/public/platform/WebRect.h" 100 #include "third_party/WebKit/public/platform/WebRect.h"
100 #include "third_party/WebKit/public/platform/WebString.h" 101 #include "third_party/WebKit/public/platform/WebString.h"
101 #include "third_party/WebKit/public/platform/WebURL.h" 102 #include "third_party/WebKit/public/platform/WebURL.h"
102 #include "third_party/WebKit/public/platform/WebURLError.h" 103 #include "third_party/WebKit/public/platform/WebURLError.h"
103 #include "third_party/WebKit/public/platform/WebURLRequest.h" 104 #include "third_party/WebKit/public/platform/WebURLRequest.h"
104 #include "third_party/WebKit/public/web/WebBindings.h" 105 #include "third_party/WebKit/public/web/WebBindings.h"
105 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 106 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
106 #include "third_party/WebKit/public/web/WebDataSource.h" 107 #include "third_party/WebKit/public/web/WebDataSource.h"
107 #include "third_party/WebKit/public/web/WebDocument.h" 108 #include "third_party/WebKit/public/web/WebDocument.h"
108 #include "third_party/WebKit/public/web/WebInputEvent.h" 109 #include "third_party/WebKit/public/web/WebInputEvent.h"
109 #include "third_party/WebKit/public/web/WebLocalFrame.h" 110 #include "third_party/WebKit/public/web/WebLocalFrame.h"
110 #include "third_party/WebKit/public/web/WebPluginContainer.h" 111 #include "third_party/WebKit/public/web/WebPluginContainer.h"
111 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h" 112 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h"
112 #include "third_party/WebKit/public/web/WebPrintParams.h" 113 #include "third_party/WebKit/public/web/WebPrintParams.h"
113 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" 114 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h"
114 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" 115 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
115 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 116 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
116 #include "third_party/WebKit/public/web/WebScriptSource.h" 117 #include "third_party/WebKit/public/web/WebScriptSource.h"
117 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 118 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
118 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 119 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
119 #include "third_party/WebKit/public/web/WebView.h" 120 #include "third_party/WebKit/public/web/WebView.h"
120 #include "third_party/khronos/GLES2/gl2.h" 121 #include "third_party/khronos/GLES2/gl2.h"
122 #include "ui/events/blink/blink_event_util.h"
121 #include "ui/gfx/image/image_skia.h" 123 #include "ui/gfx/image/image_skia.h"
122 #include "ui/gfx/image/image_skia_rep.h" 124 #include "ui/gfx/image/image_skia_rep.h"
123 #include "ui/gfx/range/range.h" 125 #include "ui/gfx/range/range.h"
124 #include "url/origin.h" 126 #include "url/origin.h"
125 #include "v8/include/v8.h" 127 #include "v8/include/v8.h"
126 128
127 #if defined(ENABLE_PRINTING) 129 #if defined(ENABLE_PRINTING)
128 // nogncheck because dependency on //printing is conditional upon 130 // nogncheck because dependency on //printing is conditional upon
129 // enable_basic_printing or enable_print_preview flags. 131 // enable_basic_printing or enable_print_preview flags.
130 #include "printing/metafile_skia_wrapper.h" // nogncheck 132 #include "printing/metafile_skia_wrapper.h" // nogncheck
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 container_(container), 494 container_(container),
493 layer_bound_to_fullscreen_(false), 495 layer_bound_to_fullscreen_(false),
494 layer_is_hardware_(false), 496 layer_is_hardware_(false),
495 plugin_url_(plugin_url), 497 plugin_url_(plugin_url),
496 document_url_(container ? GURL(container->element().document().url()) 498 document_url_(container ? GURL(container->element().document().url())
497 : GURL()), 499 : GURL()),
498 is_flash_plugin_(module->name() == kFlashPluginName), 500 is_flash_plugin_(module->name() == kFlashPluginName),
499 has_been_clicked_(false), 501 has_been_clicked_(false),
500 javascript_used_(false), 502 javascript_used_(false),
501 full_frame_(false), 503 full_frame_(false),
504 viewport_to_dip_scale_(1.0f),
502 sent_initial_did_change_view_(false), 505 sent_initial_did_change_view_(false),
503 bound_graphics_2d_platform_(NULL), 506 bound_graphics_2d_platform_(NULL),
504 bound_compositor_(NULL), 507 bound_compositor_(NULL),
505 has_webkit_focus_(false), 508 has_webkit_focus_(false),
506 has_content_area_focus_(false), 509 has_content_area_focus_(false),
507 find_identifier_(-1), 510 find_identifier_(-1),
508 plugin_find_interface_(NULL), 511 plugin_find_interface_(NULL),
509 plugin_input_event_interface_(NULL), 512 plugin_input_event_interface_(NULL),
510 plugin_mouse_lock_interface_(NULL), 513 plugin_mouse_lock_interface_(NULL),
511 plugin_pdf_interface_(NULL), 514 plugin_pdf_interface_(NULL),
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after
1076 } 1079 }
1077 1080
1078 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const { 1081 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const {
1079 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || 1082 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) ||
1080 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); 1083 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME);
1081 } 1084 }
1082 1085
1083 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const { 1086 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const {
1084 if (!text_input_caret_set_) { 1087 if (!text_input_caret_set_) {
1085 // If it is never set by the plugin, use the bottom left corner. 1088 // If it is never set by the plugin, use the bottom left corner.
1086 return gfx::Rect(view_data_.rect.point.x, 1089 gfx::Rect rect(view_data_.rect.point.x,
1087 view_data_.rect.point.y + view_data_.rect.size.height, 1090 view_data_.rect.point.y + view_data_.rect.size.height,
1088 0, 1091 0, 0);
1089 0); 1092 ConvertDIPToViewport(&rect);
1093 return rect;
1090 } 1094 }
1091 1095
1092 // TODO(kinaba) Take CSS transformation into accont. 1096 // TODO(kinaba) Take CSS transformation into account.
1093 // TODO(kinaba) Take bounding_box into account. On some platforms, an 1097 // TODO(kinaba) Take |text_input_caret_bounds_| into account. On
1094 // "exclude rectangle" where candidate window must avoid the region can be 1098 // some platforms, an "exclude rectangle" where candidate window
1095 // passed to IME. Currently, we pass only the caret rectangle because 1099 // must avoid the region can be passed to IME. Currently, we pass
1096 // it is the only information supported uniformly in Chromium. 1100 // only the caret rectangle because it is the only information
1101 // supported uniformly in Chromium.
1097 gfx::Rect caret(text_input_caret_); 1102 gfx::Rect caret(text_input_caret_);
1098 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); 1103 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
1104 ConvertDIPToViewport(&caret);
1099 return caret; 1105 return caret;
1100 } 1106 }
1101 1107
1102 bool PepperPluginInstanceImpl::HandleInputEvent( 1108 bool PepperPluginInstanceImpl::HandleInputEvent(
1103 const blink::WebInputEvent& event, 1109 const blink::WebInputEvent& event,
1104 WebCursorInfo* cursor_info) { 1110 WebCursorInfo* cursor_info) {
1105 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); 1111 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent");
1106 1112
1107 if (!has_been_clicked_ && is_flash_plugin_ && 1113 if (!has_been_clicked_ && is_flash_plugin_ &&
1108 event.type == blink::WebInputEvent::MouseDown && 1114 event.type == blink::WebInputEvent::MouseDown &&
1109 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { 1115 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
1110 has_been_clicked_ = true; 1116 has_been_clicked_ = true;
1111 blink::WebRect bounds = container()->element().boundsInViewport(); 1117 blink::WebRect bounds = container()->element().boundsInViewport();
1118 render_frame()->GetRenderWidget()->convertViewportToWindow(&bounds);
1112 RecordFlashClickSizeMetric(bounds.width, bounds.height); 1119 RecordFlashClickSizeMetric(bounds.width, bounds.height);
1113 } 1120 }
1114 1121
1115 if (throttler_ && throttler_->ConsumeInputEvent(event)) 1122 if (throttler_ && throttler_->ConsumeInputEvent(event))
1116 return true; 1123 return true;
1117 1124
1118 if (!render_frame_) 1125 if (!render_frame_)
1119 return false; 1126 return false;
1120 if (WebInputEvent::isMouseEventType(event.type)) { 1127 if (WebInputEvent::isMouseEventType(event.type)) {
1121 render_frame_->PepperDidReceiveMouseEvent(this); 1128 render_frame_->PepperDidReceiveMouseEvent(this);
(...skipping 13 matching lines...) Expand all
1135 bool rv = false; 1142 bool rv = false;
1136 if (LoadInputEventInterface()) { 1143 if (LoadInputEventInterface()) {
1137 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); 1144 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type);
1138 if (!event_class) 1145 if (!event_class)
1139 return false; 1146 return false;
1140 1147
1141 if ((filtered_input_event_mask_ & event_class) || 1148 if ((filtered_input_event_mask_ & event_class) ||
1142 (input_event_mask_ & event_class)) { 1149 (input_event_mask_ & event_class)) {
1143 // Actually send the event. 1150 // Actually send the event.
1144 std::vector<ppapi::InputEventData> events; 1151 std::vector<ppapi::InputEventData> events;
1145 CreateInputEventData(event, &events); 1152 scoped_ptr<const WebInputEvent> event_in_dip(
1153 ui::ScaleWebInputEvent(event, viewport_to_dip_scale_));
1154 if (event_in_dip)
1155 CreateInputEventData(*event_in_dip.get(), &events);
1156 else
1157 CreateInputEventData(event, &events);
1146 1158
1147 // Allow the user gesture to be pending after the plugin handles the 1159 // Allow the user gesture to be pending after the plugin handles the
1148 // event. This allows out-of-process plugins to respond to the user 1160 // event. This allows out-of-process plugins to respond to the user
1149 // gesture after processing has finished here. 1161 // gesture after processing has finished here.
1150 if (WebUserGestureIndicator::isProcessingUserGesture()) { 1162 if (WebUserGestureIndicator::isProcessingUserGesture()) {
1151 pending_user_gesture_ = 1163 pending_user_gesture_ =
1152 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); 1164 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now());
1153 pending_user_gesture_token_ = 1165 pending_user_gesture_token_ =
1154 WebUserGestureIndicator::currentUserGestureToken(); 1166 WebUserGestureIndicator::currentUserGestureToken();
1155 pending_user_gesture_token_.setOutOfProcess(); 1167 pending_user_gesture_token_.setOutOfProcess();
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 1264
1253 unobscured_rect_ = unobscured; 1265 unobscured_rect_ = unobscured;
1254 1266
1255 cut_outs_rects_ = cut_outs_rects; 1267 cut_outs_rects_ = cut_outs_rects;
1256 1268
1257 view_data_.rect = PP_FromGfxRect(window); 1269 view_data_.rect = PP_FromGfxRect(window);
1258 view_data_.clip_rect = PP_FromGfxRect(clip); 1270 view_data_.clip_rect = PP_FromGfxRect(clip);
1259 view_data_.device_scale = container_->deviceScaleFactor(); 1271 view_data_.device_scale = container_->deviceScaleFactor();
1260 view_data_.css_scale = 1272 view_data_.css_scale =
1261 container_->pageZoomFactor() * container_->pageScaleFactor(); 1273 container_->pageZoomFactor() * container_->pageScaleFactor();
1274 blink::WebFloatRect windowToViewportScale(0, 0, 1.0f, 0);
1275 render_frame()->GetRenderWidget()->convertWindowToViewport(
1276 &windowToViewportScale);
1277 viewport_to_dip_scale_ = 1.0f / windowToViewportScale.width;
1278 ConvertRectToDIP(&view_data_.rect);
1279 ConvertRectToDIP(&view_data_.clip_rect);
1280 view_data_.css_scale *= viewport_to_dip_scale_;
1281 view_data_.device_scale /= viewport_to_dip_scale_;
1262 1282
1263 gfx::Size scroll_offset = 1283 gfx::Size scroll_offset =
1264 container_->element().document().frame()->scrollOffset(); 1284 container_->element().document().frame()->scrollOffset();
1265 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(), 1285 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(),
1266 scroll_offset.height()); 1286 scroll_offset.height());
1267 1287
1268 if (desired_fullscreen_state_ || view_data_.is_fullscreen) { 1288 if (desired_fullscreen_state_ || view_data_.is_fullscreen) {
1269 WebElement element = container_->element(); 1289 WebElement element = container_->element();
1270 WebDocument document = element.document(); 1290 WebDocument document = element.document();
1271 bool is_fullscreen_element = (element == document.fullScreenElement()); 1291 bool is_fullscreen_element = (element == document.fullScreenElement());
(...skipping 2024 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 } 3316 }
3297 3317
3298 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { 3318 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() {
3299 if (initialized_ && !javascript_used_ && is_flash_plugin_) { 3319 if (initialized_ && !javascript_used_ && is_flash_plugin_) {
3300 javascript_used_ = true; 3320 javascript_used_ = true;
3301 RenderThread::Get()->RecordAction( 3321 RenderThread::Get()->RecordAction(
3302 base::UserMetricsAction("Flash.JavaScriptUsed")); 3322 base::UserMetricsAction("Flash.JavaScriptUsed"));
3303 } 3323 }
3304 } 3324 }
3305 3325
3326 void PepperPluginInstanceImpl::ConvertRectToDIP(PP_Rect* rect) const {
3327 rect->point.x *= viewport_to_dip_scale_;
3328 rect->point.y *= viewport_to_dip_scale_;
3329 rect->size.width *= viewport_to_dip_scale_;
3330 rect->size.height *= viewport_to_dip_scale_;
3331 }
3332
3333 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const {
3334 rect->set_x(rect->x() / viewport_to_dip_scale_);
3335 rect->set_y(rect->y() / viewport_to_dip_scale_);
3336 rect->set_width(rect->width() / viewport_to_dip_scale_);
3337 rect->set_height(rect->height() / viewport_to_dip_scale_);
3338 }
3339
3306 } // namespace content 3340 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_plugin_instance_impl.h ('k') | ui/events/blink/blink_event_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698