| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2009, 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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 RefPtrWillBeRawPtr<Range> markerRange = selectionRange->cloneRange(); | 124 RefPtrWillBeRawPtr<Range> markerRange = selectionRange->cloneRange(); |
| 125 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset
()); | 125 markerRange->setStart(markerRange->startContainer(), markers[0]->startOffset
()); |
| 126 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); | 126 markerRange->setEnd(markerRange->endContainer(), markers[0]->endOffset()); |
| 127 | 127 |
| 128 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec
tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 128 if (markerRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation) != selec
tionRange->text().stripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 129 return String(); | 129 return String(); |
| 130 | 130 |
| 131 return markerRange->text(); | 131 return markerRange->text(); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu) | 134 void ContextMenuClientImpl::setupContextMenuData(HitTestResult& r, WebContextMen
uData& data, const Event* event) |
| 135 { | 135 { |
| 136 // Displaying the context menu in this function is a big hack as we don't | |
| 137 // have context, i.e. whether this is being invoked via a script or in | |
| 138 // response to user input (Mouse event WM_RBUTTONDOWN, | |
| 139 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked | |
| 140 // in response to the above input events before popping up the context menu. | |
| 141 if (!ContextMenuAllowedScope::isContextMenuAllowed()) | |
| 142 return; | |
| 143 | |
| 144 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult()
; | |
| 145 | |
| 146 r.setToShadowHostIfInUserAgentShadowRoot(); | |
| 147 | |
| 148 LocalFrame* selectedFrame = r.innerNodeFrame(); | |
| 149 | |
| 150 WebContextMenuData data; | |
| 151 data.mousePosition = selectedFrame->view()->contentsToViewport(r.roundedPoin
tInInnerNodeFrame()); | |
| 152 | |
| 153 // Compute edit flags. | |
| 154 data.editFlags = WebContextMenuData::CanDoNone; | |
| 155 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canUndo()) | |
| 156 data.editFlags |= WebContextMenuData::CanUndo; | |
| 157 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canRedo()) | |
| 158 data.editFlags |= WebContextMenuData::CanRedo; | |
| 159 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canCut()) | |
| 160 data.editFlags |= WebContextMenuData::CanCut; | |
| 161 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canCopy()) | |
| 162 data.editFlags |= WebContextMenuData::CanCopy; | |
| 163 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canPaste()) | |
| 164 data.editFlags |= WebContextMenuData::CanPaste; | |
| 165 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canDelete()) | |
| 166 data.editFlags |= WebContextMenuData::CanDelete; | |
| 167 // We can always select all... | |
| 168 data.editFlags |= WebContextMenuData::CanSelectAll; | |
| 169 data.editFlags |= WebContextMenuData::CanTranslate; | |
| 170 | |
| 171 // Links, Images, Media tags, and Image/Media-Links take preference over | 136 // Links, Images, Media tags, and Image/Media-Links take preference over |
| 172 // all else. | 137 // all else. |
| 173 data.linkURL = r.absoluteLinkURL(); | 138 data.linkURL = r.absoluteLinkURL(); |
| 174 | 139 |
| 175 if (r.innerNode()->isHTMLElement()) { | 140 if (r.innerNode()->isHTMLElement()) { |
| 176 HTMLElement* htmlElement = toHTMLElement(r.innerNode()); | 141 HTMLElement* htmlElement = toHTMLElement(r.innerNode()); |
| 177 if (!htmlElement->title().isEmpty()) { | 142 if (!htmlElement->title().isEmpty()) { |
| 178 data.titleText = htmlElement->title(); | 143 data.titleText = htmlElement->title(); |
| 179 } else { | 144 } else { |
| 180 data.titleText = htmlElement->altText(); | 145 data.titleText = htmlElement->altText(); |
| 181 } | 146 } |
| 182 } | 147 } |
| 183 | 148 |
| 184 if (isHTMLCanvasElement(r.innerNode())) { | 149 if (isHTMLCanvasElement(r.innerNode())) { |
| 185 data.mediaType = WebContextMenuData::MediaTypeCanvas; | 150 data.mediaType = WebContextMenuData::MediaTypeCanvas; |
| 186 data.hasImageContents = true; | 151 data.hasImageContents = true; |
| 187 } else if (!r.absoluteImageURL().isEmpty()) { | 152 } else if (!r.absoluteImageURL().isEmpty()) { |
| 188 data.srcURL = r.absoluteImageURL(); | 153 data.srcURL = r.absoluteImageURL(); |
| 189 data.mediaType = WebContextMenuData::MediaTypeImage; | 154 data.mediaType = WebContextMenuData::MediaTypeImage; |
| 190 data.mediaFlags |= WebContextMenuData::MediaCanPrint; | 155 data.mediaFlags |= WebContextMenuData::MediaCanPrint; |
| 191 | 156 |
| 192 // An image can be null for many reasons, like being blocked, no image | 157 // An image can be null for many reasons, like being blocked, no image |
| 193 // data received from server yet. | 158 // data received from server yet. |
| 194 data.hasImageContents = r.image() && !r.image()->isNull(); | 159 data.hasImageContents = r.image() && !r.image()->isNull(); |
| 195 if (data.hasImageContents && isHTMLImageElement(r.innerNodeOrImageMapIma
ge())) { | 160 if (data.hasImageContents && isHTMLImageElement(r.innerNodeOrImageMapIma
ge())) { |
| 161 // An imageMap get mouse location as parameters. |
| 162 StringBuilder url; |
| 163 IntPoint clampedPoint; |
| 164 bool success = HTMLAnchorElement::getClampedPointFromEvent(clampedPo
int, event); |
| 165 if (success) { |
| 166 HTMLAnchorElement::appendServerMapMousePosition(url, clampedPoin
t); |
| 167 data.linkURL = KURL(data.linkURL, url.toString()); |
| 168 } |
| 169 |
| 196 HTMLImageElement* imageElement = toHTMLImageElement(r.innerNodeOrIma
geMapImage()); | 170 HTMLImageElement* imageElement = toHTMLImageElement(r.innerNodeOrIma
geMapImage()); |
| 197 if (imageElement && imageElement->cachedImage()) | 171 if (imageElement && imageElement->cachedImage()) |
| 198 data.imageResponse = WrappedResourceResponse(imageElement->cache
dImage()->response()); | 172 data.imageResponse = WrappedResourceResponse(imageElement->cache
dImage()->response()); |
| 199 } | 173 } |
| 200 } else if (!r.absoluteMediaURL().isEmpty()) { | 174 } else if (!r.absoluteMediaURL().isEmpty()) { |
| 201 data.srcURL = r.absoluteMediaURL(); | 175 data.srcURL = r.absoluteMediaURL(); |
| 202 | 176 |
| 203 // We know that if absoluteMediaURL() is not empty, then this | 177 // We know that if absoluteMediaURL() is not empty, then this |
| 204 // is a media element. | 178 // is a media element. |
| 205 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNode()); | 179 HTMLMediaElement* mediaElement = toHTMLMediaElement(r.innerNode()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 HTMLPlugInElement* pluginElement = toHTMLPlugInElement(r.innerNo
de()); | 222 HTMLPlugInElement* pluginElement = toHTMLPlugInElement(r.innerNo
de()); |
| 249 data.srcURL = pluginElement->document().completeURL(pluginElemen
t->url()); | 223 data.srcURL = pluginElement->document().completeURL(pluginElemen
t->url()); |
| 250 data.mediaFlags |= WebContextMenuData::MediaCanSave; | 224 data.mediaFlags |= WebContextMenuData::MediaCanSave; |
| 251 | 225 |
| 252 // Add context menu commands that are supported by the plugin. | 226 // Add context menu commands that are supported by the plugin. |
| 253 if (plugin->plugin()->canRotateView()) | 227 if (plugin->plugin()->canRotateView()) |
| 254 data.mediaFlags |= WebContextMenuData::MediaCanRotate; | 228 data.mediaFlags |= WebContextMenuData::MediaCanRotate; |
| 255 } | 229 } |
| 256 } | 230 } |
| 257 } | 231 } |
| 232 } |
| 233 |
| 234 void ContextMenuClientImpl::showContextMenu(const ContextMenu* defaultMenu, cons
t Event* event) |
| 235 { |
| 236 // Displaying the context menu in this function is a big hack as we don't |
| 237 // have context, i.e. whether this is being invoked via a script or in |
| 238 // response to user input (Mouse event WM_RBUTTONDOWN, |
| 239 // Keyboard events KeyVK_APPS, Shift+F10). Check if this is being invoked |
| 240 // in response to the above input events before popping up the context menu. |
| 241 if (!ContextMenuAllowedScope::isContextMenuAllowed()) |
| 242 return; |
| 243 |
| 244 HitTestResult r = m_webView->page()->contextMenuController().hitTestResult()
; |
| 245 |
| 246 r.setToShadowHostIfInUserAgentShadowRoot(); |
| 247 |
| 248 LocalFrame* selectedFrame = r.innerNodeFrame(); |
| 249 |
| 250 WebContextMenuData data; |
| 251 data.mousePosition = selectedFrame->view()->contentsToViewport(r.roundedPoin
tInInnerNodeFrame()); |
| 252 |
| 253 // Compute edit flags. |
| 254 data.editFlags = WebContextMenuData::CanDoNone; |
| 255 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canUndo()) |
| 256 data.editFlags |= WebContextMenuData::CanUndo; |
| 257 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canRedo()) |
| 258 data.editFlags |= WebContextMenuData::CanRedo; |
| 259 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canCut()) |
| 260 data.editFlags |= WebContextMenuData::CanCut; |
| 261 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canCopy()) |
| 262 data.editFlags |= WebContextMenuData::CanCopy; |
| 263 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canPaste()) |
| 264 data.editFlags |= WebContextMenuData::CanPaste; |
| 265 if (toLocalFrame(m_webView->focusedCoreFrame())->editor().canDelete()) |
| 266 data.editFlags |= WebContextMenuData::CanDelete; |
| 267 // We can always select all... |
| 268 data.editFlags |= WebContextMenuData::CanSelectAll; |
| 269 data.editFlags |= WebContextMenuData::CanTranslate; |
| 270 |
| 271 // setup WebContextMenuData from HitTestResult and Event |
| 272 setupContextMenuData(r, data, event); |
| 258 | 273 |
| 259 // If it's not a link, an image, a media element, or an image/media link, | 274 // If it's not a link, an image, a media element, or an image/media link, |
| 260 // show a selection menu or a more generic page menu. | 275 // show a selection menu or a more generic page menu. |
| 261 if (selectedFrame->document()->loader()) | 276 if (selectedFrame->document()->loader()) |
| 262 data.frameEncoding = selectedFrame->document()->encodingName(); | 277 data.frameEncoding = selectedFrame->document()->encodingName(); |
| 263 | 278 |
| 264 // Send the frame and page URLs in any case. | 279 // Send the frame and page URLs in any case. |
| 265 if (!m_webView->page()->mainFrame()->isLocalFrame()) { | 280 if (!m_webView->page()->mainFrame()->isLocalFrame()) { |
| 266 // TODO(kenrb): This works around the problem of URLs not being | 281 // TODO(kenrb): This works around the problem of URLs not being |
| 267 // available for top-level frames that are in a different process. | 282 // available for top-level frames that are in a different process. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 outputItems[i] = subItems[i]; | 429 outputItems[i] = subItems[i]; |
| 415 subMenuItems.swap(outputItems); | 430 subMenuItems.swap(outputItems); |
| 416 } | 431 } |
| 417 | 432 |
| 418 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe
nu, WebContextMenuData* data) | 433 void ContextMenuClientImpl::populateCustomMenuItems(const ContextMenu* defaultMe
nu, WebContextMenuData* data) |
| 419 { | 434 { |
| 420 populateSubMenuItems(defaultMenu->items(), data->customItems); | 435 populateSubMenuItems(defaultMenu->items(), data->customItems); |
| 421 } | 436 } |
| 422 | 437 |
| 423 } // namespace blink | 438 } // namespace blink |
| OLD | NEW |