Changeset 113956 in webkit
- Timestamp:
- Apr 12, 2012 2:59:33 AM (12 years ago)
- Location:
- trunk/Source/WebKit/chromium
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/chromium/ChangeLog
r113948 r113956 1 2012-04-12 Kent Tamura <tkent@chromium.org> 2 3 [Chromium] Add PagePopup implementation 4 https://bugs.webkit.org/show_bug.cgi?id=81081 5 6 Reviewed by Adam Barth. 7 8 Add WebPagePopupImpl class, which is an implementation of 9 WebCore::PagePopup interface and WebKit::WebPagePopup interface. It's a 10 WebWidget which has a Page object. 11 12 No new tests because this makes no behavior change yet. 13 14 * WebKit.gyp: Add WebPagePopupImpl.h. 15 * src/ChromeClientImpl.cpp: 16 (WebKit::ChromeClientImpl::hasOpenedPopup): Supports the PagePopup. 17 (WebKit::ChromeClientImpl::openPagePopup): 18 just delegate to WebViewImpl::openPagePopup(). 19 (WebKit::ChromeClientImpl::closePagePopup): ditto. 20 21 * src/WebPagePopupImpl.cpp: 22 (PagePopupChromeClient): 23 This is a light implementation of ChromeClient for the page in 24 WebPagePopupImpl. This is a friend of WebPagePopupImpl becase of ease of 25 access to its members. 26 (WebKit::PagePopupChromeClient::PagePopupChromeClient): 27 (WebKit::WebPagePopupImpl::WebPagePopupImpl): 28 (WebKit::WebPagePopupImpl::~WebPagePopupImpl): 29 (WebKit::WebPagePopupImpl::init): 30 (WebKit::WebPagePopupImpl::initPage): 31 (WebKit::WebPagePopupImpl::size): 32 (WebKit::WebPagePopupImpl::animate): Calls PageWidgetDelegate::animate(). 33 (WebKit::WebPagePopupImpl::composite): 34 (WebKit::WebPagePopupImpl::layout): Calls PageWidgetDelegate::layout(). 35 (WebKit::WebPagePopupImpl::paint): Calls PageWidgetDelegate::paint(). 36 (WebKit::WebPagePopupImpl::resize): 37 (WebKit::WebPagePopupImpl::handleKeyEvent): 38 (WebKit::WebPagePopupImpl::handleCharEvent): 39 (WebKit::WebPagePopupImpl::handleGestureEvent): 40 (WebKit::WebPagePopupImpl::handleInputEvent): 41 (WebKit::WebPagePopupImpl::setFocus): 42 (WebKit::WebPagePopupImpl::close): Delete the page, and kill itself. 43 (WebKit::WebPagePopupImpl::closePopup): 44 (WebKit::WebPagePopup::create): 45 * src/WebPagePopupImpl.h: Added. 46 47 * src/WebViewImpl.cpp: 48 (WebKit::WebViewImpl::WebViewImpl): Initialize m_pagePopup. 49 (WebKit::WebViewImpl::handleKeyEvent): 50 Renamed from keyEvent(). Forward key events to a PagePopup if it is open. 51 (WebKit::WebViewImpl::handleCharEvent): 52 Renamed from charEvent(). Forward char events to a PagePopup if it is open. 53 (WebKit::WebViewImpl::openPagePopup): 54 Added. Instantiate a WebPagePopupImpl, calculates a good bounding 55 rectangle of the page popup from the specified element rectangle, 56 initialize the WebPagePopupImpl, and stop caret blink. 57 (WebKit::WebViewImpl::closePagePopup): 58 Close the popup, clear m_pagePopup, and resume caret blink. 59 (WebKit::WebViewImpl::setFocus): Hide all the popups. 60 (WebKit::WebViewImpl::hidePopups): Hide the page popup too. 61 * src/WebViewImpl.h: 62 (WebKit::WebViewImpl::hasOpenedPopup): Checks the page popup too. 63 1 64 2012-04-12 Kent Tamura <tkent@chromium.org> 2 65 -
trunk/Source/WebKit/chromium/WebKit.gyp
r113948 r113956 614 614 'src/WebOptionElement.cpp', 615 615 'src/WebPagePopupImpl.cpp', 616 'src/WebPagePopupImpl.h', 616 617 'src/WebPageSerializer.cpp', 617 618 'src/WebPageSerializerImpl.cpp', -
trunk/Source/WebKit/chromium/src/ChromeClientImpl.cpp
r113782 r113956 978 978 bool ChromeClientImpl::hasOpenedPopup() const 979 979 { 980 return !!m_webView->selectPopup();980 return m_webView->hasOpenedPopup(); 981 981 } 982 982 … … 995 995 996 996 #if ENABLE(PAGE_POPUP) 997 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient*, const IntRect&) 998 { 999 // FIXME: Impelement this. 1000 return 0; 1001 } 1002 1003 void ChromeClientImpl::closePagePopup(PagePopup*) 1004 { 1005 // FIXME: Implement this. 997 PagePopup* ChromeClientImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView) 998 { 999 return m_webView->openPagePopup(client, originBoundsInRootView); 1000 } 1001 1002 void ChromeClientImpl::closePagePopup(PagePopup* popup) 1003 { 1004 m_webView->closePagePopup(popup); 1006 1005 } 1007 1006 #endif -
trunk/Source/WebKit/chromium/src/WebPagePopupImpl.cpp
r109816 r113956 1 1 /* 2 * Copyright (C) 20 09Google Inc. All rights reserved.2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 30 30 31 31 #include "config.h" 32 32 #include "WebPagePopupImpl.h" 33 34 #include "EmptyClients.h" 35 #include "FileChooser.h" 36 #include "FocusController.h" 37 #include "FormState.h" 38 #include "FrameView.h" 39 #include "HTMLFormElement.h" 40 #include "Page.h" 41 #include "PagePopupClient.h" 42 #include "PageWidgetDelegate.h" 43 #include "Settings.h" 44 #include "WebInputEvent.h" 45 #include "WebInputEventConversion.h" 33 46 #include "WebPagePopup.h" 47 #include "WebWidgetClient.h" 48 49 using namespace WebCore; 34 50 35 51 namespace WebKit { 36 52 53 #if ENABLE(PAGE_POPUP) 54 55 class PagePopupChromeClient : public EmptyChromeClient { 56 WTF_MAKE_NONCOPYABLE(PagePopupChromeClient); 57 WTF_MAKE_FAST_ALLOCATED; 58 59 public: 60 explicit PagePopupChromeClient(WebPagePopupImpl* popup) 61 : m_popup(popup) 62 { 63 ASSERT(m_popup->widgetClient()); 64 } 65 66 private: 67 virtual void closeWindowSoon() OVERRIDE 68 { 69 m_popup->closePopup(); 70 } 71 72 virtual FloatRect windowRect() OVERRIDE 73 { 74 return FloatRect(m_popup->m_windowRectInScreen.x, m_popup->m_windowRectInScreen.y, m_popup->m_windowRectInScreen.width, m_popup->m_windowRectInScreen.height); 75 } 76 77 virtual void setWindowRect(const FloatRect& rect) OVERRIDE 78 { 79 m_popup->m_windowRectInScreen = IntRect(rect); 80 m_popup->widgetClient()->setWindowRect(m_popup->m_windowRectInScreen); 81 } 82 83 virtual void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned int lineNumber, const String&) OVERRIDE 84 { 85 #ifndef NDEBUG 86 fprintf(stderr, "CONSOLE MESSSAGE:%u: %s\n", lineNumber, message.utf8().data()); 87 #else 88 UNUSED_PARAM(message); 89 UNUSED_PARAM(lineNumber); 90 #endif 91 } 92 93 virtual void invalidateContentsAndRootView(const IntRect& paintRect, bool) OVERRIDE 94 { 95 if (paintRect.isEmpty()) 96 return; 97 m_popup->widgetClient()->didInvalidateRect(paintRect); 98 } 99 100 virtual void scroll(const IntSize& scrollDelta, const IntRect& scrollRect, const IntRect& clipRect) OVERRIDE 101 { 102 m_popup->widgetClient()->didScrollRect(scrollDelta.width(), scrollDelta.height(), intersection(scrollRect, clipRect)); 103 } 104 105 virtual void invalidateContentsForSlowScroll(const IntRect& updateRect, bool immediate) OVERRIDE 106 { 107 invalidateContentsAndRootView(updateRect, immediate); 108 } 109 110 virtual void scheduleAnimation() OVERRIDE 111 { 112 m_popup->widgetClient()->scheduleAnimation(); 113 } 114 115 virtual void* webView() const OVERRIDE 116 { 117 return m_popup->m_webView; 118 } 119 120 WebPagePopupImpl* m_popup; 121 }; 122 37 123 // WebPagePopupImpl ---------------------------------------------------------------- 38 124 39 // FIXME: WebPagePopupImpl implementation will be written here. 125 WebPagePopupImpl::WebPagePopupImpl(WebWidgetClient* client) 126 : m_widgetClient(client) 127 { 128 ASSERT(client); 129 } 130 131 WebPagePopupImpl::~WebPagePopupImpl() 132 { 133 ASSERT(!m_page); 134 } 135 136 bool WebPagePopupImpl::init(WebViewImpl* webView, PagePopupClient* popupClient, const IntRect& boundsInScreen) 137 { 138 ASSERT(webView); 139 ASSERT(popupClient); 140 m_webView = webView; 141 m_popupClient = popupClient; 142 143 m_widgetClient->setWindowRect(boundsInScreen); 144 m_windowRectInScreen = boundsInScreen; 145 if (!initPage()) 146 return false; 147 m_widgetClient->show(WebNavigationPolicy()); 148 149 setFocus(true); 150 151 return true; 152 } 153 154 bool WebPagePopupImpl::initPage() 155 { 156 Page::PageClients pageClients; 157 fillWithEmptyClients(pageClients); 158 m_chromeClient = adoptPtr(new PagePopupChromeClient(this)); 159 pageClients.chromeClient = m_chromeClient.get(); 160 161 m_page = adoptPtr(new Page(pageClients)); 162 m_page->settings()->setScriptEnabled(true); 163 m_page->settings()->setAllowScriptsToCloseWindows(true); 164 165 static FrameLoaderClient* emptyFrameLoaderClient = new EmptyFrameLoaderClient; 166 RefPtr<Frame> frame = Frame::create(m_page.get(), 0, emptyFrameLoaderClient); 167 frame->setView(FrameView::create(frame.get())); 168 frame->init(); 169 frame->view()->resize(m_popupClient->contentSize()); 170 frame->view()->setTransparent(false); 171 172 DocumentWriter* writer = frame->loader()->activeDocumentLoader()->writer(); 173 writer->setMIMEType("text/html"); 174 writer->setEncoding("UTF-8", false); 175 writer->begin(); 176 m_popupClient->writeDocument(*writer); 177 writer->end(); 178 179 frame->script()->installFunctionsForPagePopup(frame.get(), m_popupClient); 180 return true; 181 } 182 183 WebSize WebPagePopupImpl::size() 184 { 185 return m_popupClient->contentSize(); 186 } 187 188 void WebPagePopupImpl::animate(double) 189 { 190 PageWidgetDelegate::animate(m_page.get(), monotonicallyIncreasingTime()); 191 } 192 193 void WebPagePopupImpl::composite(bool) 194 { 195 } 196 197 void WebPagePopupImpl::layout() 198 { 199 PageWidgetDelegate::layout(m_page.get()); 200 } 201 202 void WebPagePopupImpl::paint(WebCanvas* canvas, const WebRect& rect) 203 { 204 PageWidgetDelegate::paint(m_page.get(), 0, canvas, rect); 205 } 206 207 void WebPagePopupImpl::resize(const WebSize& newSize) 208 { 209 if (m_page) 210 m_page->mainFrame()->view()->resize(newSize); 211 m_widgetClient->didInvalidateRect(WebRect(0, 0, newSize.width, newSize.height)); 212 } 213 214 bool WebPagePopupImpl::handleKeyEvent(const WebKeyboardEvent&) 215 { 216 // The main WebView receives key events and forward them to this via handleKeyEvent(). 217 ASSERT_NOT_REACHED(); 218 return false; 219 } 220 221 bool WebPagePopupImpl::handleCharEvent(const WebKeyboardEvent&) 222 { 223 // The main WebView receives key events and forward them to this via handleKeyEvent(). 224 ASSERT_NOT_REACHED(); 225 return false; 226 } 227 228 #if ENABLE(GESTURE_EVENTS) 229 bool WebPagePopupImpl::handleGestureEvent(const WebGestureEvent& event) 230 { 231 if (!m_page || !m_page->mainFrame() || !m_page->mainFrame()->view()) 232 return false; 233 Frame& frame = *m_page->mainFrame(); 234 return frame.eventHandler()->handleGestureEvent(PlatformGestureEventBuilder(frame.view(), event)); 235 } 236 #endif 237 238 bool WebPagePopupImpl::handleInputEvent(const WebInputEvent& event) 239 { 240 return PageWidgetDelegate::handleInputEvent(m_page.get(), *this, event); 241 } 242 243 bool WebPagePopupImpl::handleKeyEvent(const PlatformKeyboardEvent& event) 244 { 245 if (!m_page->mainFrame() || !m_page->mainFrame()->view()) 246 return false; 247 return m_page->mainFrame()->eventHandler()->keyEvent(event); 248 } 249 250 void WebPagePopupImpl::setFocus(bool enable) 251 { 252 if (!m_page) 253 return; 254 m_page->focusController()->setFocused(enable); 255 if (enable) 256 m_page->focusController()->setActive(true); 257 } 258 259 void WebPagePopupImpl::close() 260 { 261 m_page.clear(); 262 delete this; 263 } 264 265 void WebPagePopupImpl::closePopup() 266 { 267 if (m_page) { 268 m_page->setGroupName(String()); 269 m_page->mainFrame()->loader()->stopAllLoaders(); 270 m_page->mainFrame()->loader()->stopLoading(UnloadEventPolicyNone); 271 } 272 // closeWidgetSoon() will call this->close() later. 273 m_widgetClient->closeWidgetSoon(); 274 275 m_popupClient->didClosePopup(); 276 } 277 278 #endif // ENABLE(PAGE_POPUP) 40 279 41 280 // WebPagePopup ---------------------------------------------------------------- 42 281 43 WebPagePopup* WebPagePopup::create(WebWidgetClient*) 44 { 45 // FIXME: Returns a WebPagePopupImpl object. 282 WebPagePopup* WebPagePopup::create(WebWidgetClient* client) 283 { 284 #if ENABLE(PAGE_POPUP) 285 if (!client) 286 CRASH(); 287 return new WebPagePopupImpl(client); 288 #else 289 UNUSED_PARAM(client); 46 290 return 0; 291 #endif 47 292 } 48 293 -
trunk/Source/WebKit/chromium/src/WebViewImpl.cpp
r113948 r113956 89 89 #include "PageGroup.h" 90 90 #include "PageGroupLoadDeferrer.h" 91 #include "PagePopupClient.h" 91 92 #include "PageWidgetDelegate.h" 92 93 #include "Pasteboard.h" … … 132 133 #include "WebMediaPlayerAction.h" 133 134 #include "WebNode.h" 135 #include "WebPagePopupImpl.h" 134 136 #include "WebPlugin.h" 135 137 #include "WebPluginAction.h" … … 371 373 , m_autofillPopupShowing(false) 372 374 , m_autofillPopup(0) 375 , m_pagePopup(0) 373 376 , m_isTransparent(false) 374 377 , m_tabsToLinks(false) … … 716 719 if (m_selectPopup) 717 720 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 721 #if ENABLE(PAGE_POPUP) 722 if (m_pagePopup) { 723 m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 724 // We need to ignore the next Char event after this otherwise pressing 725 // enter when selecting an item in the popup will go to the page. 726 if (WebInputEvent::RawKeyDown == event.type) 727 m_suppressNextKeypressEvent = true; 728 return true; 729 } 730 #endif 718 731 719 732 // Give Autocomplete a chance to consume the key events it is interested in. … … 828 841 if (m_selectPopup) 829 842 return m_selectPopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 843 #if ENABLE(PAGE_POPUP) 844 if (m_pagePopup) 845 return m_pagePopup->handleKeyEvent(PlatformKeyboardEventBuilder(event)); 846 #endif 830 847 831 848 Frame* frame = focusedWebCoreFrame(); … … 1178 1195 } 1179 1196 1197 #if ENABLE(PAGE_POPUP) 1198 PagePopup* WebViewImpl::openPagePopup(PagePopupClient* client, const IntRect& originBoundsInRootView) 1199 { 1200 ASSERT(client); 1201 if (hasOpenedPopup()) 1202 hidePopups(); 1203 ASSERT(!m_pagePopup); 1204 1205 WebWidget* popupWidget = m_client->createPopupMenu(WebPopupTypePage); 1206 ASSERT(popupWidget); 1207 m_pagePopup = static_cast<WebPagePopupImpl*>(popupWidget); 1208 WebSize rootViewSize = size(); 1209 IntSize popupSize = client->contentSize(); 1210 IntRect popupBoundsInRootView(IntPoint(max(0, originBoundsInRootView.x()), max(0, originBoundsInRootView.maxY())), popupSize); 1211 if (popupBoundsInRootView.maxY() > rootViewSize.height) 1212 popupBoundsInRootView.setY(max(0, originBoundsInRootView.y() - popupSize.height())); 1213 if (popupBoundsInRootView.maxX() > rootViewSize.width) 1214 popupBoundsInRootView.setX(max(0, rootViewSize.width - popupSize.width())); 1215 if (!m_pagePopup->init(this, client, m_chromeClientImpl.rootViewToScreen(popupBoundsInRootView))) { 1216 m_pagePopup->closePopup(); 1217 m_pagePopup = 0; 1218 } 1219 1220 if (Frame* frame = focusedWebCoreFrame()) 1221 frame->selection()->setCaretVisible(false); 1222 return m_pagePopup; 1223 } 1224 1225 void WebViewImpl::closePagePopup(PagePopup* popup) 1226 { 1227 ASSERT(popup); 1228 WebPagePopupImpl* popupImpl = static_cast<WebPagePopupImpl*>(popup); 1229 ASSERT(m_pagePopup == popupImpl); 1230 if (m_pagePopup != popupImpl) 1231 return; 1232 m_pagePopup->closePopup(); 1233 m_pagePopup = 0; 1234 1235 if (Frame* frame = focusedWebCoreFrame()) 1236 frame->selection()->pageActivationChanged(); 1237 } 1238 #endif 1239 1180 1240 void WebViewImpl::hideAutofillPopup() 1181 1241 { … … 1645 1705 m_imeAcceptEvents = true; 1646 1706 } else { 1647 hideAutofillPopup(); 1648 hideSelectPopup(); 1707 hidePopups(); 1649 1708 1650 1709 // Clear focus on the currently focused frame if any. … … 2735 2794 hideSelectPopup(); 2736 2795 hideAutofillPopup(); 2796 #if ENABLE(PAGE_POPUP) 2797 if (m_pagePopup) 2798 closePagePopup(m_pagePopup); 2799 #endif 2737 2800 } 2738 2801 -
trunk/Source/WebKit/chromium/src/WebViewImpl.h
r113948 r113956 70 70 class KeyboardEvent; 71 71 class Page; 72 class PagePopup; 73 class PagePopupClient; 72 74 class PlatformGestureCurveTarget; 73 75 class PlatformKeyboardEvent; … … 98 100 class WebFrameImpl; 99 101 class WebGestureEvent; 102 class WebPagePopupImpl; 100 103 class WebImage; 101 104 class WebKeyboardEvent; … … 448 451 void popupOpened(WebCore::PopupContainer* popupContainer); 449 452 void popupClosed(WebCore::PopupContainer* popupContainer); 453 #if ENABLE(PAGE_POPUP) 454 WebCore::PagePopup* openPagePopup(WebCore::PagePopupClient*, const WebCore::IntRect& originBoundsInRootView); 455 void closePagePopup(WebCore::PagePopup*); 456 #endif 450 457 451 458 void hideAutofillPopup(); … … 486 493 487 494 WebCore::PopupContainer* selectPopup() const { return m_selectPopup.get(); } 495 #if ENABLE(PAGE_POPUP) 496 bool hasOpenedPopup() const { return m_selectPopup || m_pagePopup; } 497 #else 498 bool hasOpenedPopup() const { return m_selectPopup; } 499 #endif 488 500 489 501 // Returns true if the event leads to scrolling. … … 696 708 // The popup associated with a select element. 697 709 RefPtr<WebCore::PopupContainer> m_selectPopup; 710 711 #if ENABLE(PAGE_POPUP) 712 // The popup associated with an input element. 713 WebPagePopupImpl* m_pagePopup; 714 #endif 698 715 699 716 OwnPtr<WebDevToolsAgentPrivate> m_devToolsAgent;
Note: See TracChangeset
for help on using the changeset viewer.