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

Side by Side Diff: third_party/WebKit/Source/web/WebPagePopupImpl.cpp

Issue 1456753002: Compute the popup location/size correctly when use-zoom-for-dsf is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years 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 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 68
69 class PagePopupChromeClient final : public EmptyChromeClient { 69 class PagePopupChromeClient final : public EmptyChromeClient {
70 public: 70 public:
71 static PassOwnPtrWillBeRawPtr<PagePopupChromeClient> create(WebPagePopupImpl * popup) 71 static PassOwnPtrWillBeRawPtr<PagePopupChromeClient> create(WebPagePopupImpl * popup)
72 { 72 {
73 return adoptPtrWillBeNoop(new PagePopupChromeClient(popup)); 73 return adoptPtrWillBeNoop(new PagePopupChromeClient(popup));
74 } 74 }
75 75
76 void setWindowRect(const IntRect& rect) override 76 void setWindowRect(const IntRect& rect) override
77 { 77 {
78 m_popup->m_windowRectInScreen = rect; 78 m_popup->setWindowRect(rect);
79 m_popup->widgetClient()->setWindowRect(m_popup->m_windowRectInScreen);
80 } 79 }
81 80
82 private: 81 private:
83 explicit PagePopupChromeClient(WebPagePopupImpl* popup) 82 explicit PagePopupChromeClient(WebPagePopupImpl* popup)
84 : m_popup(popup) 83 : m_popup(popup)
85 { 84 {
86 ASSERT(m_popup->widgetClient()); 85 ASSERT(m_popup->widgetClient());
87 } 86 }
88 87
89 void closeWindowSoon() override 88 void closeWindowSoon() override
90 { 89 {
91 m_popup->closePopup(); 90 m_popup->closePopup();
92 } 91 }
93 92
94 IntRect windowRect() override 93 IntRect windowRect() override
95 { 94 {
96 return IntRect(m_popup->m_windowRectInScreen.x, m_popup->m_windowRectInS creen.y, m_popup->m_windowRectInScreen.width, m_popup->m_windowRectInScreen.heig ht); 95 return m_popup->m_windowRectInScreen;
97 } 96 }
98 97
99 IntRect viewportToScreen(const IntRect& rect) const override 98 IntRect viewportToScreen(const IntRect& rect) const override
100 { 99 {
101 IntRect rectInScreen(rect); 100 WebRect rectInScreen(rect);
102 rectInScreen.move(m_popup->m_windowRectInScreen.x, m_popup->m_windowRect InScreen.y); 101 m_popup->widgetClient()->convertViewportToWindow(&rectInScreen);
102 rectInScreen.x += m_popup->m_windowRectInScreen.x;
103 rectInScreen.y += m_popup->m_windowRectInScreen.y;
103 return rectInScreen; 104 return rectInScreen;
104 } 105 }
105 106
106 void addMessageToConsole(LocalFrame*, MessageSource, MessageLevel, const Str ing& message, unsigned lineNumber, const String&, const String&) override 107 void addMessageToConsole(LocalFrame*, MessageSource, MessageLevel, const Str ing& message, unsigned lineNumber, const String&, const String&) override
107 { 108 {
108 #ifndef NDEBUG 109 #ifndef NDEBUG
109 fprintf(stderr, "CONSOLE MESSSAGE:%u: %s\n", lineNumber, message.utf8(). data()); 110 fprintf(stderr, "CONSOLE MESSSAGE:%u: %s\n", lineNumber, message.utf8(). data());
110 #endif 111 #endif
111 } 112 }
112 113
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 bool WebPagePopupImpl::initializePage() 242 bool WebPagePopupImpl::initializePage()
242 { 243 {
243 Page::PageClients pageClients; 244 Page::PageClients pageClients;
244 fillWithEmptyClients(pageClients); 245 fillWithEmptyClients(pageClients);
245 m_chromeClient = PagePopupChromeClient::create(this); 246 m_chromeClient = PagePopupChromeClient::create(this);
246 pageClients.chromeClient = m_chromeClient.get(); 247 pageClients.chromeClient = m_chromeClient.get();
247 248
248 m_page = adoptPtrWillBeNoop(new Page(pageClients)); 249 m_page = adoptPtrWillBeNoop(new Page(pageClients));
249 m_page->settings().setScriptEnabled(true); 250 m_page->settings().setScriptEnabled(true);
250 m_page->settings().setAllowScriptsToCloseWindows(true); 251 m_page->settings().setAllowScriptsToCloseWindows(true);
251 m_page->setDeviceScaleFactor(m_webView->deviceScaleFactor());
252 m_page->settings().setDeviceSupportsTouch(m_webView->page()->settings().devi ceSupportsTouch()); 252 m_page->settings().setDeviceSupportsTouch(m_webView->page()->settings().devi ceSupportsTouch());
253 // FIXME: Should we support enabling a11y while a popup is shown? 253 // FIXME: Should we support enabling a11y while a popup is shown?
254 m_page->settings().setAccessibilityEnabled(m_webView->page()->settings().acc essibilityEnabled()); 254 m_page->settings().setAccessibilityEnabled(m_webView->page()->settings().acc essibilityEnabled());
255 m_page->settings().setScrollAnimatorEnabled(m_webView->page()->settings().sc rollAnimatorEnabled()); 255 m_page->settings().setScrollAnimatorEnabled(m_webView->page()->settings().sc rollAnimatorEnabled());
256 256
257 provideContextFeaturesTo(*m_page, adoptPtr(new PagePopupFeaturesClient())); 257 provideContextFeaturesTo(*m_page, adoptPtr(new PagePopupFeaturesClient()));
258 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<FrameLoaderClient>, emptyFrameLoa derClient, (EmptyFrameLoaderClient::create())); 258 DEFINE_STATIC_LOCAL(OwnPtrWillBePersistent<FrameLoaderClient>, emptyFrameLoa derClient, (EmptyFrameLoaderClient::create()));
259 RefPtrWillBeRawPtr<LocalFrame> frame = LocalFrame::create(emptyFrameLoaderCl ient.get(), &m_page->frameHost(), 0); 259 RefPtrWillBeRawPtr<LocalFrame> frame = LocalFrame::create(emptyFrameLoaderCl ient.get(), &m_page->frameHost(), 0);
260 frame->setPagePopupOwner(m_popupClient->ownerElement()); 260 frame->setPagePopupOwner(m_popupClient->ownerElement());
261 frame->setView(FrameView::create(frame.get())); 261 frame->setView(FrameView::create(frame.get()));
262 frame->init(); 262 frame->init();
263 frame->view()->setTransparent(false); 263 frame->view()->setTransparent(false);
264 if (AXObjectCache* cache = m_popupClient->ownerElement().document().existing AXObjectCache()) 264 if (AXObjectCache* cache = m_popupClient->ownerElement().document().existing AXObjectCache())
265 cache->childrenChanged(&m_popupClient->ownerElement()); 265 cache->childrenChanged(&m_popupClient->ownerElement());
266 266
267 ASSERT(frame->localDOMWindow()); 267 ASSERT(frame->localDOMWindow());
268 DOMWindowPagePopup::install(*frame->localDOMWindow(), *this, m_popupClient); 268 DOMWindowPagePopup::install(*frame->localDOMWindow(), *this, m_popupClient);
269 ASSERT(m_popupClient->ownerElement().document().existingAXObjectCache() == f rame->document()->existingAXObjectCache()); 269 ASSERT(m_popupClient->ownerElement().document().existingAXObjectCache() == f rame->document()->existingAXObjectCache());
270 270
271 RefPtr<SharedBuffer> data = SharedBuffer::create(); 271 RefPtr<SharedBuffer> data = SharedBuffer::create();
272 m_popupClient->writeDocument(data.get()); 272 m_popupClient->writeDocument(data.get());
273 frame->loader().load(FrameLoadRequest(0, blankURL(), SubstituteData(data, "t ext/html", "UTF-8", KURL(), ForceSynchronousLoad))); 273 frame->loader().load(FrameLoadRequest(0, blankURL(), SubstituteData(data, "t ext/html", "UTF-8", KURL(), ForceSynchronousLoad)));
274 frame->setPageZoomFactor(m_popupClient->zoomFactor()); 274 frame->setPageZoomFactor(m_popupClient->zoomFactor());
275
276 return true; 275 return true;
277 } 276 }
278 277
279 void WebPagePopupImpl::postMessage(const String& message) 278 void WebPagePopupImpl::postMessage(const String& message)
280 { 279 {
281 if (!m_page) 280 if (!m_page)
282 return; 281 return;
283 ScriptForbiddenScope::AllowUserAgentScript allowScript; 282 ScriptForbiddenScope::AllowUserAgentScript allowScript;
284 if (LocalDOMWindow* window = toLocalFrame(m_page->mainFrame())->localDOMWind ow()) 283 if (LocalDOMWindow* window = toLocalFrame(m_page->mainFrame())->localDOMWind ow())
285 window->dispatchEvent(MessageEvent::create(message)); 284 window->dispatchEvent(MessageEvent::create(message));
(...skipping 13 matching lines...) Expand all
299 if (!m_page || !m_page->mainFrame()) 298 if (!m_page || !m_page->mainFrame())
300 return 0; 299 return 0;
301 Document* document = toLocalFrame(m_page->mainFrame())->document(); 300 Document* document = toLocalFrame(m_page->mainFrame())->document();
302 if (!document) 301 if (!document)
303 return 0; 302 return 0;
304 AXObjectCache* cache = document->axObjectCache(); 303 AXObjectCache* cache = document->axObjectCache();
305 ASSERT(cache); 304 ASSERT(cache);
306 return toAXObjectCacheImpl(cache)->getOrCreate(document->layoutView()); 305 return toAXObjectCacheImpl(cache)->getOrCreate(document->layoutView());
307 } 306 }
308 307
309 void WebPagePopupImpl::setWindowRect(const IntRect& rect) 308 void WebPagePopupImpl::setWindowRect(const IntRect& rectInScreen)
310 { 309 {
311 m_chromeClient->setWindowRect(rect); 310 m_windowRectInScreen = rectInScreen;
311 widgetClient()->setWindowRect(m_windowRectInScreen);
312 } 312 }
313 313
314 void WebPagePopupImpl::setRootGraphicsLayer(GraphicsLayer* layer) 314 void WebPagePopupImpl::setRootGraphicsLayer(GraphicsLayer* layer)
315 { 315 {
316 m_rootGraphicsLayer = layer; 316 m_rootGraphicsLayer = layer;
317 m_rootLayer = layer ? layer->platformLayer() : 0; 317 m_rootLayer = layer ? layer->platformLayer() : 0;
318 318
319 setIsAcceleratedCompositingActive(layer); 319 setIsAcceleratedCompositingActive(layer);
320 if (m_layerTreeView) { 320 if (m_layerTreeView) {
321 if (m_rootLayer) { 321 if (m_rootLayer) {
(...skipping 14 matching lines...) Expand all
336 } else if (m_layerTreeView) { 336 } else if (m_layerTreeView) {
337 m_isAcceleratedCompositingActive = true; 337 m_isAcceleratedCompositingActive = true;
338 } else { 338 } else {
339 TRACE_EVENT0("blink", "WebPagePopupImpl::setIsAcceleratedCompositingActi ve(true)"); 339 TRACE_EVENT0("blink", "WebPagePopupImpl::setIsAcceleratedCompositingActi ve(true)");
340 340
341 m_widgetClient->initializeLayerTreeView(); 341 m_widgetClient->initializeLayerTreeView();
342 m_layerTreeView = m_widgetClient->layerTreeView(); 342 m_layerTreeView = m_widgetClient->layerTreeView();
343 if (m_layerTreeView) { 343 if (m_layerTreeView) {
344 m_layerTreeView->setVisible(true); 344 m_layerTreeView->setVisible(true);
345 m_isAcceleratedCompositingActive = true; 345 m_isAcceleratedCompositingActive = true;
346 m_layerTreeView->setDeviceScaleFactor(m_webView->deviceScaleFactor() );
347 m_page->layerTreeViewInitialized(*m_layerTreeView); 346 m_page->layerTreeViewInitialized(*m_layerTreeView);
348 } else { 347 } else {
349 m_isAcceleratedCompositingActive = false; 348 m_isAcceleratedCompositingActive = false;
350 } 349 }
351 } 350 }
352 } 351 }
353 352
354 void WebPagePopupImpl::beginFrame(double lastFrameTimeMonotonic) 353 void WebPagePopupImpl::beginFrame(double lastFrameTimeMonotonic)
355 { 354 {
356 if (!m_page) 355 if (!m_page)
(...skipping 18 matching lines...) Expand all
375 return; 374 return;
376 PageWidgetDelegate::updateAllLifecyclePhases(*m_page, *m_page->deprecatedLoc alMainFrame()); 375 PageWidgetDelegate::updateAllLifecyclePhases(*m_page, *m_page->deprecatedLoc alMainFrame());
377 } 376 }
378 377
379 void WebPagePopupImpl::paint(WebCanvas* canvas, const WebRect& rect) 378 void WebPagePopupImpl::paint(WebCanvas* canvas, const WebRect& rect)
380 { 379 {
381 if (!m_closing) 380 if (!m_closing)
382 PageWidgetDelegate::paint(*m_page, canvas, rect, *m_page->deprecatedLoca lMainFrame()); 381 PageWidgetDelegate::paint(*m_page, canvas, rect, *m_page->deprecatedLoca lMainFrame());
383 } 382 }
384 383
385 void WebPagePopupImpl::resize(const WebSize& newSize) 384 void WebPagePopupImpl::resize(const WebSize& newSizeInViewport)
386 { 385 {
387 m_windowRectInScreen = WebRect(m_windowRectInScreen.x, m_windowRectInScreen. y, newSize.width, newSize.height); 386 WebRect newSize(0, 0, newSizeInViewport.width, newSizeInViewport.height);
388 m_widgetClient->setWindowRect(m_windowRectInScreen); 387 widgetClient()->convertViewportToWindow(&newSize);
389 388
389 setWindowRect(WebRect(m_windowRectInScreen.x, m_windowRectInScreen.y, newSiz e.width, newSize.height));
390 if (m_page) { 390 if (m_page) {
391 toLocalFrame(m_page->mainFrame())->view()->resize(newSize); 391 toLocalFrame(m_page->mainFrame())->view()->resize(newSizeInViewport);
392 m_page->frameHost().visualViewport().setSize(newSize); 392 m_page->frameHost().visualViewport().setSize(newSizeInViewport);
393 } 393 }
394 394
395 m_widgetClient->didInvalidateRect(WebRect(0, 0, newSize.width, newSize.heigh t)); 395 m_widgetClient->didInvalidateRect(WebRect(0, 0, newSize.width, newSize.heigh t));
396 } 396 }
397 397
398 WebInputEventResult WebPagePopupImpl::handleKeyEvent(const WebKeyboardEvent& eve nt) 398 WebInputEventResult WebPagePopupImpl::handleKeyEvent(const WebKeyboardEvent& eve nt)
399 { 399 {
400 return handleKeyEvent(PlatformKeyboardEventBuilder(event)); 400 return handleKeyEvent(PlatformKeyboardEventBuilder(event));
401 } 401 }
402 402
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 // A WebPagePopupImpl instance usually has two references. 536 // A WebPagePopupImpl instance usually has two references.
537 // - One owned by the instance itself. It represents the visible widget. 537 // - One owned by the instance itself. It represents the visible widget.
538 // - One owned by a WebViewImpl. It's released when the WebViewImpl ask the 538 // - One owned by a WebViewImpl. It's released when the WebViewImpl ask the
539 // WebPagePopupImpl to close. 539 // WebPagePopupImpl to close.
540 // We need them because the closing operation is asynchronous and the widget 540 // We need them because the closing operation is asynchronous and the widget
541 // can be closed while the WebViewImpl is unaware of it. 541 // can be closed while the WebViewImpl is unaware of it.
542 return adoptRef(new WebPagePopupImpl(client)).leakRef(); 542 return adoptRef(new WebPagePopupImpl(client)).leakRef();
543 } 543 }
544 544
545 } // namespace blink 545 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698