| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 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 30 matching lines...) Expand all Loading... |
| 41 #include "HitTestResult.h" | 41 #include "HitTestResult.h" |
| 42 #include "HTMLMediaElement.h" | 42 #include "HTMLMediaElement.h" |
| 43 #include "HTMLNames.h" | 43 #include "HTMLNames.h" |
| 44 #include "KURL.h" | 44 #include "KURL.h" |
| 45 #include "MediaError.h" | 45 #include "MediaError.h" |
| 46 #include "PlatformString.h" | 46 #include "PlatformString.h" |
| 47 #include "TextBreakIterator.h" | 47 #include "TextBreakIterator.h" |
| 48 #include "Widget.h" | 48 #include "Widget.h" |
| 49 | 49 |
| 50 #include "WebContextMenuData.h" | 50 #include "WebContextMenuData.h" |
| 51 #include "WebFrame.h" | 51 #include "WebDataSourceImpl.h" |
| 52 #include "WebFrameImpl.h" |
| 52 #include "WebPoint.h" | 53 #include "WebPoint.h" |
| 53 #include "WebString.h" | 54 #include "WebString.h" |
| 54 #include "WebURL.h" | 55 #include "WebURL.h" |
| 55 #include "WebURLResponse.h" | 56 #include "WebURLResponse.h" |
| 56 #include "WebViewClient.h" | 57 #include "WebViewClient.h" |
| 57 #include "WebDataSourceImpl.h" | 58 #include "WebViewImpl.h" |
| 58 #undef LOG | |
| 59 | |
| 60 // FIXME: Temporary hack until WebViewImpl is in api/src. | |
| 61 #include "webkit/glue/webview_impl.h" | |
| 62 | 59 |
| 63 using namespace WebCore; | 60 using namespace WebCore; |
| 64 | 61 |
| 65 namespace WebKit { | 62 namespace WebKit { |
| 66 | 63 |
| 67 // Figure out the URL of a page or subframe. Returns |page_type| as the type, | 64 // Figure out the URL of a page or subframe. Returns |page_type| as the type, |
| 68 // which indicates page or subframe, or ContextNodeType::NONE if the URL could not | 65 // which indicates page or subframe, or ContextNodeType::NONE if the URL could not |
| 69 // be determined for some reason. | 66 // be determined for some reason. |
| 70 static WebURL urlFromFrame(Frame* frame) | 67 static WebURL urlFromFrame(Frame* frame) |
| 71 { | 68 { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 133 } |
| 137 | 134 |
| 138 PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems( | 135 PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems( |
| 139 ContextMenu* defaultMenu) | 136 ContextMenu* defaultMenu) |
| 140 { | 137 { |
| 141 // Displaying the context menu in this function is a big hack as we don't | 138 // Displaying the context menu in this function is a big hack as we don't |
| 142 // have context, i.e. whether this is being invoked via a script or in | 139 // have context, i.e. whether this is being invoked via a script or in |
| 143 // response to user input (Mouse event WM_RBUTTONDOWN, | 140 // response to user input (Mouse event WM_RBUTTONDOWN, |
| 144 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked | 141 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
| 145 // in response to the above input events before popping up the context menu. | 142 // in response to the above input events before popping up the context menu. |
| 146 if (!m_webView->context_menu_allowed()) | 143 if (!m_webView->contextMenuAllowed()) |
| 147 return 0; | 144 return 0; |
| 148 | 145 |
| 149 HitTestResult r = defaultMenu->hitTestResult(); | 146 HitTestResult r = defaultMenu->hitTestResult(); |
| 150 Frame* selectedFrame = r.innerNonSharedNode()->document()->frame(); | 147 Frame* selectedFrame = r.innerNonSharedNode()->document()->frame(); |
| 151 | 148 |
| 152 WebContextMenuData data; | 149 WebContextMenuData data; |
| 153 data.mousePosition = selectedFrame->view()->contentsToWindow(r.point()); | 150 data.mousePosition = selectedFrame->view()->contentsToWindow(r.point()); |
| 154 | 151 |
| 155 // Links, Images, Media tags, and Image/Media-Links take preference over | 152 // Links, Images, Media tags, and Image/Media-Links take preference over |
| 156 // all else. | 153 // all else. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 185 if (mediaElement->supportsSave()) | 182 if (mediaElement->supportsSave()) |
| 186 data.mediaFlags |= WebContextMenuData::MediaCanSave; | 183 data.mediaFlags |= WebContextMenuData::MediaCanSave; |
| 187 if (mediaElement->hasAudio()) | 184 if (mediaElement->hasAudio()) |
| 188 data.mediaFlags |= WebContextMenuData::MediaHasAudio; | 185 data.mediaFlags |= WebContextMenuData::MediaHasAudio; |
| 189 } | 186 } |
| 190 // If it's not a link, an image, a media element, or an image/media link, | 187 // If it's not a link, an image, a media element, or an image/media link, |
| 191 // show a selection menu or a more generic page menu. | 188 // show a selection menu or a more generic page menu. |
| 192 data.frameEncoding = selectedFrame->loader()->encoding(); | 189 data.frameEncoding = selectedFrame->loader()->encoding(); |
| 193 | 190 |
| 194 // Send the frame and page URLs in any case. | 191 // Send the frame and page URLs in any case. |
| 195 data.pageURL = urlFromFrame(m_webView->main_frame()->frame()); | 192 data.pageURL = urlFromFrame(m_webView->mainFrameImpl()->frame()); |
| 196 if (selectedFrame != m_webView->main_frame()->frame()) | 193 if (selectedFrame != m_webView->mainFrameImpl()->frame()) |
| 197 data.frameURL = urlFromFrame(selectedFrame); | 194 data.frameURL = urlFromFrame(selectedFrame); |
| 198 | 195 |
| 199 if (r.isSelected()) | 196 if (r.isSelected()) |
| 200 data.selectedText = selectedFrame->selectedText().stripWhiteSpace(); | 197 data.selectedText = selectedFrame->selectedText().stripWhiteSpace(); |
| 201 | 198 |
| 202 data.isEditable = false; | 199 data.isEditable = false; |
| 203 if (r.isContentEditable()) { | 200 if (r.isContentEditable()) { |
| 204 data.isEditable = true; | 201 data.isEditable = true; |
| 205 if (m_webView->GetFocusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) { | 202 if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) { |
| 206 data.isSpellCheckingEnabled = true; | 203 data.isSpellCheckingEnabled = true; |
| 207 data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame); | 204 data.misspelledWord = selectMisspelledWord(defaultMenu, selectedFrame); |
| 208 } | 205 } |
| 209 } | 206 } |
| 210 | 207 |
| 211 // Now retrieve the security info. | 208 // Now retrieve the security info. |
| 212 DocumentLoader* dl = selectedFrame->loader()->documentLoader(); | 209 DocumentLoader* dl = selectedFrame->loader()->documentLoader(); |
| 213 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); | 210 WebDataSource* ds = WebDataSourceImpl::fromDocumentLoader(dl); |
| 214 if (ds) | 211 if (ds) |
| 215 data.securityInfo = ds->response().securityInfo(); | 212 data.securityInfo = ds->response().securityInfo(); |
| 216 | 213 |
| 217 // Compute edit flags. | 214 // Compute edit flags. |
| 218 data.editFlags = WebContextMenuData::CanDoNone; | 215 data.editFlags = WebContextMenuData::CanDoNone; |
| 219 if (m_webView->GetFocusedWebCoreFrame()->editor()->canUndo()) | 216 if (m_webView->focusedWebCoreFrame()->editor()->canUndo()) |
| 220 data.editFlags |= WebContextMenuData::CanUndo; | 217 data.editFlags |= WebContextMenuData::CanUndo; |
| 221 if (m_webView->GetFocusedWebCoreFrame()->editor()->canRedo()) | 218 if (m_webView->focusedWebCoreFrame()->editor()->canRedo()) |
| 222 data.editFlags |= WebContextMenuData::CanRedo; | 219 data.editFlags |= WebContextMenuData::CanRedo; |
| 223 if (m_webView->GetFocusedWebCoreFrame()->editor()->canCut()) | 220 if (m_webView->focusedWebCoreFrame()->editor()->canCut()) |
| 224 data.editFlags |= WebContextMenuData::CanCut; | 221 data.editFlags |= WebContextMenuData::CanCut; |
| 225 if (m_webView->GetFocusedWebCoreFrame()->editor()->canCopy()) | 222 if (m_webView->focusedWebCoreFrame()->editor()->canCopy()) |
| 226 data.editFlags |= WebContextMenuData::CanCopy; | 223 data.editFlags |= WebContextMenuData::CanCopy; |
| 227 if (m_webView->GetFocusedWebCoreFrame()->editor()->canPaste()) | 224 if (m_webView->focusedWebCoreFrame()->editor()->canPaste()) |
| 228 data.editFlags |= WebContextMenuData::CanPaste; | 225 data.editFlags |= WebContextMenuData::CanPaste; |
| 229 if (m_webView->GetFocusedWebCoreFrame()->editor()->canDelete()) | 226 if (m_webView->focusedWebCoreFrame()->editor()->canDelete()) |
| 230 data.editFlags |= WebContextMenuData::CanDelete; | 227 data.editFlags |= WebContextMenuData::CanDelete; |
| 231 // We can always select all... | 228 // We can always select all... |
| 232 data.editFlags |= WebContextMenuData::CanSelectAll; | 229 data.editFlags |= WebContextMenuData::CanSelectAll; |
| 233 | 230 |
| 234 WebFrame* selected_web_frame = WebFrameImpl::FromFrame(selectedFrame); | 231 WebFrame* selected_web_frame = WebFrameImpl::fromFrame(selectedFrame); |
| 235 if (m_webView->client()) | 232 if (m_webView->client()) |
| 236 m_webView->client()->showContextMenu(selected_web_frame, data); | 233 m_webView->client()->showContextMenu(selected_web_frame, data); |
| 237 | 234 |
| 238 return 0; | 235 return 0; |
| 239 } | 236 } |
| 240 | 237 |
| 241 } // namespace WebKit | 238 } // namespace WebKit |
| OLD | NEW |