| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 markers[0]->StartOffset()); | 127 markers[0]->StartOffset()); |
| 128 marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); | 128 marker_range->setEnd(marker_range->endContainer(), markers[0]->EndOffset()); |
| 129 | 129 |
| 130 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != | 130 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) != |
| 131 selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) | 131 selection_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation)) |
| 132 return String(); | 132 return String(); |
| 133 | 133 |
| 134 return marker_range->GetText(); | 134 return marker_range->GetText(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 // static |
| 138 int ContextMenuClientImpl::ComputeEditFlags(Document& selected_document, |
| 139 Editor& editor) { |
| 140 int edit_flags = WebContextMenuData::kCanDoNone; |
| 141 if (!selected_document.IsHTMLDocument() && |
| 142 !selected_document.IsXHTMLDocument()) |
| 143 return edit_flags; |
| 144 |
| 145 edit_flags |= WebContextMenuData::kCanTranslate; |
| 146 if (editor.CanUndo()) |
| 147 edit_flags |= WebContextMenuData::kCanUndo; |
| 148 if (editor.CanRedo()) |
| 149 edit_flags |= WebContextMenuData::kCanRedo; |
| 150 if (editor.CanCut()) |
| 151 edit_flags |= WebContextMenuData::kCanCut; |
| 152 if (editor.CanCopy()) |
| 153 edit_flags |= WebContextMenuData::kCanCopy; |
| 154 if (editor.CanPaste()) |
| 155 edit_flags |= WebContextMenuData::kCanPaste; |
| 156 if (editor.CanDelete()) |
| 157 edit_flags |= WebContextMenuData::kCanDelete; |
| 158 if (selected_document.queryCommandEnabled("selectAll", ASSERT_NO_EXCEPTION)) |
| 159 edit_flags |= WebContextMenuData::kCanSelectAll; |
| 160 return edit_flags; |
| 161 } |
| 162 |
| 137 bool ContextMenuClientImpl::ShouldShowContextMenuFromTouch( | 163 bool ContextMenuClientImpl::ShouldShowContextMenuFromTouch( |
| 138 const WebContextMenuData& data) { | 164 const WebContextMenuData& data) { |
| 139 return web_view_->GetPage() | 165 return web_view_->GetPage() |
| 140 ->GetSettings() | 166 ->GetSettings() |
| 141 .GetAlwaysShowContextMenuOnTouch() || | 167 .GetAlwaysShowContextMenuOnTouch() || |
| 142 !data.link_url.IsEmpty() || | 168 !data.link_url.IsEmpty() || |
| 143 data.media_type == WebContextMenuData::kMediaTypeImage || | 169 data.media_type == WebContextMenuData::kMediaTypeImage || |
| 144 data.media_type == WebContextMenuData::kMediaTypeVideo || | 170 data.media_type == WebContextMenuData::kMediaTypeVideo || |
| 145 data.is_editable; | 171 data.is_editable; |
| 146 } | 172 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 161 r.SetToShadowHostIfInRestrictedShadowRoot(); | 187 r.SetToShadowHostIfInRestrictedShadowRoot(); |
| 162 | 188 |
| 163 LocalFrame* selected_frame = r.InnerNodeFrame(); | 189 LocalFrame* selected_frame = r.InnerNodeFrame(); |
| 164 WebLocalFrameImpl* selected_web_frame = | 190 WebLocalFrameImpl* selected_web_frame = |
| 165 WebLocalFrameImpl::FromFrame(selected_frame); | 191 WebLocalFrameImpl::FromFrame(selected_frame); |
| 166 | 192 |
| 167 WebContextMenuData data; | 193 WebContextMenuData data; |
| 168 data.mouse_position = selected_frame->View()->ContentsToViewport( | 194 data.mouse_position = selected_frame->View()->ContentsToViewport( |
| 169 r.RoundedPointInInnerNodeFrame()); | 195 r.RoundedPointInInnerNodeFrame()); |
| 170 | 196 |
| 171 // Compute edit flags. | 197 data.edit_flags = ComputeEditFlags( |
| 172 data.edit_flags = WebContextMenuData::kCanDoNone; | 198 *selected_frame->GetDocument(), |
| 173 if (selected_frame->GetDocument()->IsHTMLDocument() || | 199 ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor()); |
| 174 selected_frame->GetDocument()->IsXHTMLDocument()) { | |
| 175 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanUndo()) | |
| 176 data.edit_flags |= WebContextMenuData::kCanUndo; | |
| 177 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanRedo()) | |
| 178 data.edit_flags |= WebContextMenuData::kCanRedo; | |
| 179 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanCut()) | |
| 180 data.edit_flags |= WebContextMenuData::kCanCut; | |
| 181 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanCopy()) | |
| 182 data.edit_flags |= WebContextMenuData::kCanCopy; | |
| 183 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanPaste()) | |
| 184 data.edit_flags |= WebContextMenuData::kCanPaste; | |
| 185 if (ToLocalFrame(web_view_->FocusedCoreFrame())->GetEditor().CanDelete()) | |
| 186 data.edit_flags |= WebContextMenuData::kCanDelete; | |
| 187 if (selected_frame->GetDocument()->queryCommandEnabled("selectAll", | |
| 188 ASSERT_NO_EXCEPTION)) | |
| 189 data.edit_flags |= WebContextMenuData::kCanSelectAll; | |
| 190 data.edit_flags |= WebContextMenuData::kCanTranslate; | |
| 191 } | |
| 192 | 200 |
| 193 // Links, Images, Media tags, and Image/Media-Links take preference over | 201 // Links, Images, Media tags, and Image/Media-Links take preference over |
| 194 // all else. | 202 // all else. |
| 195 data.link_url = r.AbsoluteLinkURL(); | 203 data.link_url = r.AbsoluteLinkURL(); |
| 196 | 204 |
| 197 if (r.InnerNode()->IsHTMLElement()) { | 205 if (r.InnerNode()->IsHTMLElement()) { |
| 198 HTMLElement* html_element = ToHTMLElement(r.InnerNode()); | 206 HTMLElement* html_element = ToHTMLElement(r.InnerNode()); |
| 199 if (!html_element->title().IsEmpty()) { | 207 if (!html_element->title().IsEmpty()) { |
| 200 data.title_text = html_element->title(); | 208 data.title_text = html_element->title(); |
| 201 } else { | 209 } else { |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 sub_menu_items.Swap(output_items); | 464 sub_menu_items.Swap(output_items); |
| 457 } | 465 } |
| 458 | 466 |
| 459 void ContextMenuClientImpl::PopulateCustomMenuItems( | 467 void ContextMenuClientImpl::PopulateCustomMenuItems( |
| 460 const ContextMenu* default_menu, | 468 const ContextMenu* default_menu, |
| 461 WebContextMenuData* data) { | 469 WebContextMenuData* data) { |
| 462 PopulateSubMenuItems(default_menu->Items(), data->custom_items); | 470 PopulateSubMenuItems(default_menu->Items(), data->custom_items); |
| 463 } | 471 } |
| 464 | 472 |
| 465 } // namespace blink | 473 } // namespace blink |
| OLD | NEW |