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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 this._glassPaneElement.addEventListener('mouseup', this._glassPaneMouseUp.
bind(this), false); | 75 this._glassPaneElement.addEventListener('mouseup', this._glassPaneMouseUp.
bind(this), false); |
76 this._glassPaneElement.appendChild(this.element); | 76 this._glassPaneElement.appendChild(this.element); |
77 document.body.appendChild(this._glassPaneElement); | 77 document.body.appendChild(this._glassPaneElement); |
78 this._discardMenuOnResizeListener = this._discardMenu.bind(this, true); | 78 this._discardMenuOnResizeListener = this._discardMenu.bind(this, true); |
79 document.defaultView.addEventListener('resize', this._discardMenuOnResizeL
istener, false); | 79 document.defaultView.addEventListener('resize', this._discardMenuOnResizeL
istener, false); |
80 } else { | 80 } else { |
81 this._parentMenu._parentGlassPaneElement().appendChild(this.element); | 81 this._parentMenu._parentGlassPaneElement().appendChild(this.element); |
82 } | 82 } |
83 | 83 |
84 // Re-position menu in case it does not fit. | 84 // Re-position menu in case it does not fit. |
85 var hostLeft = UI.Dialog.modalHostView().element.totalOffsetLeft(); | 85 var containerElement = UI.GlassPane.container(document); |
86 var hostRight = hostLeft + UI.Dialog.modalHostView().element.offsetWidth; | 86 var hostLeft = containerElement.totalOffsetLeft(); |
| 87 var hostRight = hostLeft + containerElement.offsetWidth; |
87 if (hostRight < this.element.offsetLeft + this.element.offsetWidth) { | 88 if (hostRight < this.element.offsetLeft + this.element.offsetWidth) { |
88 var left = this._parentMenu ? this._parentMenu.element.offsetLeft - this.e
lement.offsetWidth + subMenuOverlap : | 89 var left = this._parentMenu ? this._parentMenu.element.offsetLeft - this.e
lement.offsetWidth + subMenuOverlap : |
89 hostRight - this.element.offsetWidth; | 90 hostRight - this.element.offsetWidth; |
90 this.element.style.left = Math.max(hostLeft, left) + 'px'; | 91 this.element.style.left = Math.max(hostLeft, left) + 'px'; |
91 } | 92 } |
92 | 93 |
93 // Move submenus upwards if it does not fit. | 94 // Move submenus upwards if it does not fit. |
94 if (this._parentMenu && document.body.offsetHeight < this.element.offsetTop
+ this.element.offsetHeight) { | 95 if (this._parentMenu && document.body.offsetHeight < this.element.offsetTop
+ this.element.offsetHeight) { |
95 y = Math.max( | 96 y = Math.max(containerElement.totalOffsetTop(), document.body.offsetHeight
- this.element.offsetHeight); |
96 UI.Dialog.modalHostView().element.totalOffsetTop(), document.body.offs
etHeight - this.element.offsetHeight); | |
97 this.element.style.top = y + 'px'; | 97 this.element.style.top = y + 'px'; |
98 } | 98 } |
99 | 99 |
100 var maxHeight = UI.Dialog.modalHostView().element.offsetHeight; | 100 var maxHeight = containerElement.offsetHeight; |
101 maxHeight -= y - UI.Dialog.modalHostView().element.totalOffsetTop(); | 101 maxHeight -= y - containerElement.totalOffsetTop(); |
102 this.element.style.maxHeight = maxHeight + 'px'; | 102 this.element.style.maxHeight = maxHeight + 'px'; |
103 | 103 |
104 this._focus(); | 104 this._focus(); |
105 } | 105 } |
106 | 106 |
107 discard() { | 107 discard() { |
108 this._discardMenu(true); | 108 this._discardMenu(true); |
109 } | 109 } |
110 | 110 |
111 _parentGlassPaneElement() { | 111 _parentGlassPaneElement() { |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 388 |
389 _discardSubMenus() { | 389 _discardSubMenus() { |
390 if (this._subMenu) | 390 if (this._subMenu) |
391 this._subMenu._discardSubMenus(); | 391 this._subMenu._discardSubMenus(); |
392 if (this.element) | 392 if (this.element) |
393 this.element.remove(); | 393 this.element.remove(); |
394 if (this._parentMenu) | 394 if (this._parentMenu) |
395 delete this._parentMenu._subMenu; | 395 delete this._parentMenu._subMenu; |
396 } | 396 } |
397 }; | 397 }; |
OLD | NEW |