| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All Rights Reserved. | 2 * Copyright (C) 2011 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 | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 var targetElement = event.target; | 50 var targetElement = event.target; |
| 51 while (targetElement && window !== targetElement.ownerDocument.defaultVi
ew) { | 51 while (targetElement && window !== targetElement.ownerDocument.defaultVi
ew) { |
| 52 var frameElement = targetElement.ownerDocument.defaultView.frameElem
ent; | 52 var frameElement = targetElement.ownerDocument.defaultView.frameElem
ent; |
| 53 absoluteY += frameElement.totalOffsetTop(); | 53 absoluteY += frameElement.totalOffsetTop(); |
| 54 absoluteX += frameElement.totalOffsetLeft(); | 54 absoluteX += frameElement.totalOffsetLeft(); |
| 55 targetElement = frameElement; | 55 targetElement = frameElement; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Create context menu. | 58 // Create context menu. |
| 59 var targetRect; | 59 var targetRect; |
| 60 this._contextMenuElement = document.createElement("div"); | 60 this._contextMenuElement = document.createElementWithClass("div", "soft-
context-menu"); |
| 61 this._contextMenuElement.className = "soft-context-menu"; | |
| 62 this._contextMenuElement.tabIndex = 0; | 61 this._contextMenuElement.tabIndex = 0; |
| 63 this._contextMenuElement.style.top = absoluteY + "px"; | 62 this._contextMenuElement.style.top = absoluteY + "px"; |
| 64 this._contextMenuElement.style.left = absoluteX + "px"; | 63 this._contextMenuElement.style.left = absoluteX + "px"; |
| 65 | 64 |
| 66 this._contextMenuElement.addEventListener("mouseup", consumeEvent, false
); | 65 this._contextMenuElement.addEventListener("mouseup", consumeEvent, false
); |
| 67 this._contextMenuElement.addEventListener("keydown", this._menuKeyDown.b
ind(this), false); | 66 this._contextMenuElement.addEventListener("keydown", this._menuKeyDown.b
ind(this), false); |
| 68 | 67 |
| 69 for (var i = 0; i < this._items.length; ++i) | 68 for (var i = 0; i < this._items.length; ++i) |
| 70 this._contextMenuElement.appendChild(this._createMenuItem(this._item
s[i])); | 69 this._contextMenuElement.appendChild(this._createMenuItem(this._item
s[i])); |
| 71 | 70 |
| 72 // Install glass pane capturing events. | 71 // Install glass pane capturing events. |
| 73 if (!this._parentMenu) { | 72 if (!this._parentMenu) { |
| 74 this._glassPaneElement = document.createElement("div"); | 73 this._glassPaneElement = document.createElementWithClass("div", "sof
t-context-menu-glass-pane"); |
| 75 this._glassPaneElement.className = "soft-context-menu-glass-pane"; | |
| 76 this._glassPaneElement.tabIndex = 0; | 74 this._glassPaneElement.tabIndex = 0; |
| 77 this._glassPaneElement.addEventListener("mouseup", this._glassPaneMo
useUp.bind(this), false); | 75 this._glassPaneElement.addEventListener("mouseup", this._glassPaneMo
useUp.bind(this), false); |
| 78 this._glassPaneElement.appendChild(this._contextMenuElement); | 76 this._glassPaneElement.appendChild(this._contextMenuElement); |
| 79 document.body.appendChild(this._glassPaneElement); | 77 document.body.appendChild(this._glassPaneElement); |
| 80 this._focus(); | 78 this._focus(); |
| 81 } else | 79 } else { |
| 82 this._parentMenu._parentGlassPaneElement().appendChild(this._context
MenuElement); | 80 this._parentMenu._parentGlassPaneElement().appendChild(this._context
MenuElement); |
| 81 } |
| 83 | 82 |
| 84 // Re-position menu in case it does not fit. | 83 // Re-position menu in case it does not fit. |
| 85 if (document.body.offsetWidth < this._contextMenuElement.offsetLeft + t
his._contextMenuElement.offsetWidth) | 84 if (document.body.offsetWidth < this._contextMenuElement.offsetLeft + t
his._contextMenuElement.offsetWidth) |
| 86 this._contextMenuElement.style.left = (absoluteX - this._contextMenu
Element.offsetWidth) + "px"; | 85 this._contextMenuElement.style.left = (absoluteX - this._contextMenu
Element.offsetWidth) + "px"; |
| 87 if (document.body.offsetHeight < this._contextMenuElement.offsetTop + th
is._contextMenuElement.offsetHeight) | 86 if (document.body.offsetHeight < this._contextMenuElement.offsetTop + th
is._contextMenuElement.offsetHeight) |
| 88 this._contextMenuElement.style.top = (document.body.offsetHeight - t
his._contextMenuElement.offsetHeight) + "px"; | 87 this._contextMenuElement.style.top = (document.body.offsetHeight - t
his._contextMenuElement.offsetHeight) + "px"; |
| 89 | 88 |
| 90 event.consume(true); | 89 event.consume(true); |
| 91 }, | 90 }, |
| 92 | 91 |
| 93 _parentGlassPaneElement: function() | 92 _parentGlassPaneElement: function() |
| 94 { | 93 { |
| 95 if (this._glassPaneElement) | 94 if (this._glassPaneElement) |
| 96 return this._glassPaneElement; | 95 return this._glassPaneElement; |
| 97 if (this._parentMenu) | 96 if (this._parentMenu) |
| 98 return this._parentMenu._parentGlassPaneElement(); | 97 return this._parentMenu._parentGlassPaneElement(); |
| 99 return null; | 98 return null; |
| 100 }, | 99 }, |
| 101 | 100 |
| 102 _createMenuItem: function(item) | 101 _createMenuItem: function(item) |
| 103 { | 102 { |
| 104 if (item.type === "separator") | 103 if (item.type === "separator") |
| 105 return this._createSeparator(); | 104 return this._createSeparator(); |
| 106 | 105 |
| 107 if (item.type === "subMenu") | 106 if (item.type === "subMenu") |
| 108 return this._createSubMenu(item); | 107 return this._createSubMenu(item); |
| 109 | 108 |
| 110 var menuItemElement = document.createElement("div"); | 109 var menuItemElement = document.createElementWithClass("div", "soft-conte
xt-menu-item"); |
| 111 menuItemElement.className = "soft-context-menu-item"; | 110 var checkMarkElement = menuItemElement.createChild("span", "soft-context
-menu-item-checkmark"); |
| 112 | |
| 113 var checkMarkElement = document.createElement("span"); | |
| 114 checkMarkElement.textContent = "\u2713 "; // Checkmark Unicode symbol | 111 checkMarkElement.textContent = "\u2713 "; // Checkmark Unicode symbol |
| 115 checkMarkElement.className = "soft-context-menu-item-checkmark"; | |
| 116 if (!item.checked) | 112 if (!item.checked) |
| 117 checkMarkElement.style.opacity = "0"; | 113 checkMarkElement.style.opacity = "0"; |
| 118 | 114 |
| 119 menuItemElement.appendChild(checkMarkElement); | 115 menuItemElement.createTextChild(item.label); |
| 120 menuItemElement.appendChild(document.createTextNode(item.label)); | |
| 121 | 116 |
| 122 menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bi
nd(this), false); | 117 menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bi
nd(this), false); |
| 123 menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(t
his), false); | 118 menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(t
his), false); |
| 124 | 119 |
| 125 // Manually manage hover highlight since :hover does not work in case of
click-and-hold menu invocation. | 120 // Manually manage hover highlight since :hover does not work in case of
click-and-hold menu invocation. |
| 126 menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bi
nd(this), false); | 121 menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bi
nd(this), false); |
| 127 menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind
(this), false); | 122 menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind
(this), false); |
| 128 | 123 |
| 129 menuItemElement._actionId = item.id; | 124 menuItemElement._actionId = item.id; |
| 130 return menuItemElement; | 125 return menuItemElement; |
| 131 }, | 126 }, |
| 132 | 127 |
| 133 _createSubMenu: function(item) | 128 _createSubMenu: function(item) |
| 134 { | 129 { |
| 135 var menuItemElement = document.createElement("div"); | 130 var menuItemElement = document.createElementWithClass("div", "soft-conte
xt-menu-item"); |
| 136 menuItemElement.className = "soft-context-menu-item"; | |
| 137 menuItemElement._subItems = item.subItems; | 131 menuItemElement._subItems = item.subItems; |
| 138 | 132 |
| 139 // Occupy the same space on the left in all items. | 133 // Occupy the same space on the left in all items. |
| 140 var checkMarkElement = document.createElement("span"); | 134 var checkMarkElement = menuItemElement.createChild("span", "soft-context
-menu-item-checkmark"); |
| 141 checkMarkElement.textContent = "\u2713 "; // Checkmark Unicode symbol | 135 checkMarkElement.textContent = "\u2713 "; // Checkmark Unicode symbol |
| 142 checkMarkElement.className = "soft-context-menu-item-checkmark"; | |
| 143 checkMarkElement.style.opacity = "0"; | 136 checkMarkElement.style.opacity = "0"; |
| 144 menuItemElement.appendChild(checkMarkElement); | |
| 145 | 137 |
| 146 var subMenuArrowElement = document.createElement("span"); | 138 menuItemElement.createTextChild(item.label); |
| 139 |
| 140 var subMenuArrowElement = menuItemElement.createChild("span", "soft-cont
ext-menu-item-submenu-arrow"); |
| 147 subMenuArrowElement.textContent = "\u25B6"; // BLACK RIGHT-POINTING TRIA
NGLE | 141 subMenuArrowElement.textContent = "\u25B6"; // BLACK RIGHT-POINTING TRIA
NGLE |
| 148 subMenuArrowElement.className = "soft-context-menu-item-submenu-arrow"; | |
| 149 | |
| 150 menuItemElement.appendChild(document.createTextNode(item.label)); | |
| 151 menuItemElement.appendChild(subMenuArrowElement); | |
| 152 | 142 |
| 153 menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bi
nd(this), false); | 143 menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bi
nd(this), false); |
| 154 menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(t
his), false); | 144 menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(t
his), false); |
| 155 | 145 |
| 156 // Manually manage hover highlight since :hover does not work in case of
click-and-hold menu invocation. | 146 // Manually manage hover highlight since :hover does not work in case of
click-and-hold menu invocation. |
| 157 menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bi
nd(this), false); | 147 menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bi
nd(this), false); |
| 158 menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind
(this), false); | 148 menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind
(this), false); |
| 159 | 149 |
| 160 return menuItemElement; | 150 return menuItemElement; |
| 161 }, | 151 }, |
| 162 | 152 |
| 163 _createSeparator: function() | 153 _createSeparator: function() |
| 164 { | 154 { |
| 165 var separatorElement = document.createElement("div"); | 155 var separatorElement = document.createElementWithClass("div", "soft-cont
ext-menu-separator"); |
| 166 separatorElement.className = "soft-context-menu-separator"; | |
| 167 separatorElement._isSeparator = true; | 156 separatorElement._isSeparator = true; |
| 168 separatorElement.addEventListener("mouseover", this._hideSubMenu.bind(th
is), false); | 157 separatorElement.addEventListener("mouseover", this._hideSubMenu.bind(th
is), false); |
| 169 separatorElement.createChild("div", "separator-line"); | 158 separatorElement.createChild("div", "separator-line"); |
| 170 return separatorElement; | 159 return separatorElement; |
| 171 }, | 160 }, |
| 172 | 161 |
| 173 _menuItemMouseDown: function(event) | 162 _menuItemMouseDown: function(event) |
| 174 { | 163 { |
| 175 // Do not let separator's mouse down hit menu's handler - we need to rec
eive mouse up! | 164 // Do not let separator's mouse down hit menu's handler - we need to rec
eive mouse up! |
| 176 event.consume(true); | 165 event.consume(true); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 366 } |
| 378 | 367 |
| 379 if (!InspectorFrontendHost.showContextMenu) { | 368 if (!InspectorFrontendHost.showContextMenu) { |
| 380 | 369 |
| 381 InspectorFrontendHost.showContextMenu = function(event, items) | 370 InspectorFrontendHost.showContextMenu = function(event, items) |
| 382 { | 371 { |
| 383 new WebInspector.SoftContextMenu(items).show(event); | 372 new WebInspector.SoftContextMenu(items).show(event); |
| 384 } | 373 } |
| 385 | 374 |
| 386 } | 375 } |
| OLD | NEW |