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

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: Created 4 years, 11 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h" 113 #include "third_party/WebKit/public/web/WebPluginScriptForbiddenScope.h"
114 #include "third_party/WebKit/public/web/WebPrintParams.h" 114 #include "third_party/WebKit/public/web/WebPrintParams.h"
115 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h" 115 #include "third_party/WebKit/public/web/WebPrintPresetOptions.h"
116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h" 116 #include "third_party/WebKit/public/web/WebPrintScalingOption.h"
117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h" 117 #include "third_party/WebKit/public/web/WebScopedUserGesture.h"
118 #include "third_party/WebKit/public/web/WebScriptSource.h" 118 #include "third_party/WebKit/public/web/WebScriptSource.h"
119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 119 #include "third_party/WebKit/public/web/WebSecurityOrigin.h"
120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 120 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
121 #include "third_party/WebKit/public/web/WebView.h" 121 #include "third_party/WebKit/public/web/WebView.h"
122 #include "third_party/khronos/GLES2/gl2.h" 122 #include "third_party/khronos/GLES2/gl2.h"
123 #include "ui/events/blink/blink_event_util.h"
123 #include "ui/gfx/image/image_skia.h" 124 #include "ui/gfx/image/image_skia.h"
124 #include "ui/gfx/image/image_skia_rep.h" 125 #include "ui/gfx/image/image_skia_rep.h"
125 #include "ui/gfx/range/range.h" 126 #include "ui/gfx/range/range.h"
126 #include "url/origin.h" 127 #include "url/origin.h"
127 #include "v8/include/v8.h" 128 #include "v8/include/v8.h"
128 129
129 #if defined(OS_CHROMEOS) 130 #if defined(OS_CHROMEOS)
130 #include "ui/events/keycodes/keyboard_codes_posix.h" 131 #include "ui/events/keycodes/keyboard_codes_posix.h"
131 #endif 132 #endif
132 133
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 container_(container), 488 container_(container),
488 layer_bound_to_fullscreen_(false), 489 layer_bound_to_fullscreen_(false),
489 layer_is_hardware_(false), 490 layer_is_hardware_(false),
490 plugin_url_(plugin_url), 491 plugin_url_(plugin_url),
491 document_url_(container ? GURL(container->element().document().url()) 492 document_url_(container ? GURL(container->element().document().url())
492 : GURL()), 493 : GURL()),
493 is_flash_plugin_(module->name() == kFlashPluginName), 494 is_flash_plugin_(module->name() == kFlashPluginName),
494 has_been_clicked_(false), 495 has_been_clicked_(false),
495 javascript_used_(false), 496 javascript_used_(false),
496 full_frame_(false), 497 full_frame_(false),
498 viewport_to_dip_scale_(1.0f),
497 sent_initial_did_change_view_(false), 499 sent_initial_did_change_view_(false),
498 bound_graphics_2d_platform_(NULL), 500 bound_graphics_2d_platform_(NULL),
499 bound_compositor_(NULL), 501 bound_compositor_(NULL),
500 has_webkit_focus_(false), 502 has_webkit_focus_(false),
501 has_content_area_focus_(false), 503 has_content_area_focus_(false),
502 find_identifier_(-1), 504 find_identifier_(-1),
503 plugin_find_interface_(NULL), 505 plugin_find_interface_(NULL),
504 plugin_input_event_interface_(NULL), 506 plugin_input_event_interface_(NULL),
505 plugin_mouse_lock_interface_(NULL), 507 plugin_mouse_lock_interface_(NULL),
506 plugin_pdf_interface_(NULL), 508 plugin_pdf_interface_(NULL),
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 } 1074 }
1073 1075
1074 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const { 1076 bool PepperPluginInstanceImpl::IsPluginAcceptingCompositionEvents() const {
1075 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) || 1077 return (filtered_input_event_mask_ & PP_INPUTEVENT_CLASS_IME) ||
1076 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME); 1078 (input_event_mask_ & PP_INPUTEVENT_CLASS_IME);
1077 } 1079 }
1078 1080
1079 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const { 1081 gfx::Rect PepperPluginInstanceImpl::GetCaretBounds() const {
1080 if (!text_input_caret_set_) { 1082 if (!text_input_caret_set_) {
1081 // If it is never set by the plugin, use the bottom left corner. 1083 // If it is never set by the plugin, use the bottom left corner.
1082 return gfx::Rect(view_data_.rect.point.x, 1084 gfx::Rect rect(view_data_.rect.point.x,
1083 view_data_.rect.point.y + view_data_.rect.size.height, 1085 view_data_.rect.point.y + view_data_.rect.size.height,
1084 0, 1086 0, 0);
1085 0); 1087 ConvertDIPToViewport(&rect);
1088 return rect;
1086 } 1089 }
1087 1090
1088 // TODO(kinaba) Take CSS transformation into accont. 1091 // TODO(kinaba) Take CSS transformation into account.
1089 // TODO(kinaba) Take bounding_box into account. On some platforms, an 1092 // TODO(kinaba) Take |text_input_caret_bounds_| into account. On
1090 // "exclude rectangle" where candidate window must avoid the region can be 1093 // some platforms, an "exclude rectangle" where candidate window
1091 // passed to IME. Currently, we pass only the caret rectangle because 1094 // must avoid the region can be passed to IME. Currently, we pass
1092 // it is the only information supported uniformly in Chromium. 1095 // only the caret rectangle because it is the only information
1096 // supported uniformly in Chromium.
1093 gfx::Rect caret(text_input_caret_); 1097 gfx::Rect caret(text_input_caret_);
1094 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y); 1098 caret.Offset(view_data_.rect.point.x, view_data_.rect.point.y);
1099 ConvertDIPToViewport(&caret);
1095 return caret; 1100 return caret;
1096 } 1101 }
1097 1102
1098 bool PepperPluginInstanceImpl::HandleInputEvent( 1103 bool PepperPluginInstanceImpl::HandleInputEvent(
1099 const blink::WebInputEvent& event, 1104 const blink::WebInputEvent& event,
1100 WebCursorInfo* cursor_info) { 1105 WebCursorInfo* cursor_info) {
1101 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent"); 1106 TRACE_EVENT0("ppapi", "PepperPluginInstanceImpl::HandleInputEvent");
1102 1107
1103 if (!has_been_clicked_ && is_flash_plugin_ && 1108 if (!has_been_clicked_ && is_flash_plugin_ &&
1104 event.type == blink::WebInputEvent::MouseDown && 1109 event.type == blink::WebInputEvent::MouseDown &&
1105 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) { 1110 (event.modifiers & blink::WebInputEvent::LeftButtonDown)) {
1106 has_been_clicked_ = true; 1111 has_been_clicked_ = true;
1107 blink::WebRect bounds = container()->element().boundsInViewport(); 1112 blink::WebRect bounds = container()->element().boundsInViewport();
1113 render_frame()->GetRenderWidget()->convertViewportToWindow(&bounds);
1108 RecordFlashClickSizeMetric(bounds.width, bounds.height); 1114 RecordFlashClickSizeMetric(bounds.width, bounds.height);
1109 } 1115 }
1110 1116
1111 if (throttler_ && throttler_->ConsumeInputEvent(event)) 1117 if (throttler_ && throttler_->ConsumeInputEvent(event))
1112 return true; 1118 return true;
1113 1119
1114 if (!render_frame_) 1120 if (!render_frame_)
1115 return false; 1121 return false;
1116 if (WebInputEvent::isMouseEventType(event.type)) { 1122 if (WebInputEvent::isMouseEventType(event.type)) {
1117 render_frame_->PepperDidReceiveMouseEvent(this); 1123 render_frame_->PepperDidReceiveMouseEvent(this);
(...skipping 13 matching lines...) Expand all
1131 bool rv = false; 1137 bool rv = false;
1132 if (LoadInputEventInterface()) { 1138 if (LoadInputEventInterface()) {
1133 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type); 1139 PP_InputEvent_Class event_class = ClassifyInputEvent(event.type);
1134 if (!event_class) 1140 if (!event_class)
1135 return false; 1141 return false;
1136 1142
1137 if ((filtered_input_event_mask_ & event_class) || 1143 if ((filtered_input_event_mask_ & event_class) ||
1138 (input_event_mask_ & event_class)) { 1144 (input_event_mask_ & event_class)) {
1139 // Actually send the event. 1145 // Actually send the event.
1140 std::vector<ppapi::InputEventData> events; 1146 std::vector<ppapi::InputEventData> events;
1141 CreateInputEventData(event, &events); 1147 scoped_ptr<const WebInputEvent> event_in_dip(
1148 ui::ScaleWebInputEvent(event, viewport_to_dip_scale_));
tdresser 2016/01/21 21:14:51 Do we need a scoped_ptr here? const WebInputEvent
oshima 2016/01/22 01:22:23 yes because it needs to be deleted if the event wa
1149 if (event_in_dip)
1150 CreateInputEventData(*event_in_dip.get(), &events);
1151 else
1152 CreateInputEventData(event, &events);
1142 1153
1143 // Allow the user gesture to be pending after the plugin handles the 1154 // Allow the user gesture to be pending after the plugin handles the
1144 // event. This allows out-of-process plugins to respond to the user 1155 // event. This allows out-of-process plugins to respond to the user
1145 // gesture after processing has finished here. 1156 // gesture after processing has finished here.
1146 if (WebUserGestureIndicator::isProcessingUserGesture()) { 1157 if (WebUserGestureIndicator::isProcessingUserGesture()) {
1147 pending_user_gesture_ = 1158 pending_user_gesture_ =
1148 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now()); 1159 ppapi::TimeTicksToPPTimeTicks(base::TimeTicks::Now());
1149 pending_user_gesture_token_ = 1160 pending_user_gesture_token_ =
1150 WebUserGestureIndicator::currentUserGestureToken(); 1161 WebUserGestureIndicator::currentUserGestureToken();
1151 pending_user_gesture_token_.setOutOfProcess(); 1162 pending_user_gesture_token_.setOutOfProcess();
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 unobscured_rect_ = unobscured; 1260 unobscured_rect_ = unobscured;
1250 1261
1251 cut_outs_rects_ = cut_outs_rects; 1262 cut_outs_rects_ = cut_outs_rects;
1252 1263
1253 view_data_.rect = PP_FromGfxRect(window); 1264 view_data_.rect = PP_FromGfxRect(window);
1254 view_data_.clip_rect = PP_FromGfxRect(clip); 1265 view_data_.clip_rect = PP_FromGfxRect(clip);
1255 view_data_.device_scale = container_->deviceScaleFactor(); 1266 view_data_.device_scale = container_->deviceScaleFactor();
1256 view_data_.css_scale = 1267 view_data_.css_scale =
1257 container_->pageZoomFactor() * container_->pageScaleFactor(); 1268 container_->pageZoomFactor() * container_->pageScaleFactor();
1258 1269
1270 float windowToViewportScale =
1271 render_frame()->GetRenderWidget()->convertWindowToViewport(1.0f);
1272 viewport_to_dip_scale_ = 1.0f / windowToViewportScale;
1273 ConvertRectToDIP(&view_data_.rect);
1274 ConvertRectToDIP(&view_data_.clip_rect);
1275 view_data_.css_scale *= viewport_to_dip_scale_;
1276 view_data_.device_scale /= viewport_to_dip_scale_;
1277
1259 gfx::Size scroll_offset = 1278 gfx::Size scroll_offset =
1260 container_->element().document().frame()->scrollOffset(); 1279 container_->element().document().frame()->scrollOffset();
1261 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(), 1280 view_data_.scroll_offset = PP_MakePoint(scroll_offset.width(),
1262 scroll_offset.height()); 1281 scroll_offset.height());
1263 1282
1264 if (desired_fullscreen_state_ || view_data_.is_fullscreen) { 1283 if (desired_fullscreen_state_ || view_data_.is_fullscreen) {
1265 WebElement element = container_->element(); 1284 WebElement element = container_->element();
1266 WebDocument document = element.document(); 1285 WebDocument document = element.document();
1267 bool is_fullscreen_element = (element == document.fullScreenElement()); 1286 bool is_fullscreen_element = (element == document.fullScreenElement());
1268 if (!view_data_.is_fullscreen && desired_fullscreen_state_ && 1287 if (!view_data_.is_fullscreen && desired_fullscreen_state_ &&
(...skipping 2023 matching lines...) Expand 10 before | Expand all | Expand 10 after
3292 } 3311 }
3293 3312
3294 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() { 3313 void PepperPluginInstanceImpl::RecordFlashJavaScriptUse() {
3295 if (initialized_ && !javascript_used_ && is_flash_plugin_) { 3314 if (initialized_ && !javascript_used_ && is_flash_plugin_) {
3296 javascript_used_ = true; 3315 javascript_used_ = true;
3297 RenderThread::Get()->RecordAction( 3316 RenderThread::Get()->RecordAction(
3298 base::UserMetricsAction("Flash.JavaScriptUsed")); 3317 base::UserMetricsAction("Flash.JavaScriptUsed"));
3299 } 3318 }
3300 } 3319 }
3301 3320
3321 void PepperPluginInstanceImpl::ConvertRectToDIP(PP_Rect* rect) const {
3322 rect->point.x *= viewport_to_dip_scale_;
3323 rect->point.y *= viewport_to_dip_scale_;
3324 rect->size.width *= viewport_to_dip_scale_;
3325 rect->size.height *= viewport_to_dip_scale_;
3326 }
3327
3328 void PepperPluginInstanceImpl::ConvertDIPToViewport(gfx::Rect* rect) const {
3329 rect->set_x(rect->x() / viewport_to_dip_scale_);
3330 rect->set_y(rect->y() / viewport_to_dip_scale_);
3331 rect->set_width(rect->width() / viewport_to_dip_scale_);
3332 rect->set_height(rect->height() / viewport_to_dip_scale_);
3333 }
3334
3302 } // namespace content 3335 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698