Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(158)

Side by Side Diff: chrome/browser/resources/pdf/toolbar_manager.js

Issue 1332273003: Change the print preview UI to use the material design style buttons for zoom (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 'use strict'; 5 'use strict';
6 6
7 /** Idle time in ms before the UI is hidden. */ 7 /** Idle time in ms before the UI is hidden. */
8 var HIDE_TIMEOUT = 2000; 8 var HIDE_TIMEOUT = 2000;
9 /** Time in ms after force hide before toolbar is shown again. */ 9 /** Time in ms after force hide before toolbar is shown again. */
10 var FORCE_HIDE_TIMEOUT = 1000; 10 var FORCE_HIDE_TIMEOUT = 1000;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 this.window_.addEventListener('resize', this.resizeDropdowns_.bind(this)); 64 this.window_.addEventListener('resize', this.resizeDropdowns_.bind(this));
65 } 65 }
66 66
67 ToolbarManager.prototype = { 67 ToolbarManager.prototype = {
68 68
69 /** 69 /**
70 * Allow the toolbars to be shown. Should be called after the plugin has 70 * Allow the toolbars to be shown. Should be called after the plugin has
71 * loaded and we are ready to show a document. 71 * loaded and we are ready to show a document.
72 */ 72 */
73 enableToolbars: function() { 73 enableToolbars: function() {
74 this.toolbar_.hidden = false; 74 if (this.toolbar_)
75 this.toolbar_.hidden = false;
75 this.zoomToolbar_.hidden = false; 76 this.zoomToolbar_.hidden = false;
76 this.resizeDropdowns_(); 77 this.resizeDropdowns_();
77 }, 78 },
78 79
79 showToolbarsForMouseMove: function(e) { 80 showToolbarsForMouseMove: function(e) {
80 this.isMouseNearTopToolbar_ = isMouseNearTopToolbar(e); 81 this.isMouseNearTopToolbar_ = this.toolbar_ && isMouseNearTopToolbar(e);
81 this.isMouseNearSideToolbar_ = isMouseNearSideToolbar(e); 82 this.isMouseNearSideToolbar_ = isMouseNearSideToolbar(e);
82 83
83 // Allow the top toolbar to be shown if the mouse moves away from the side 84 // Allow the top toolbar to be shown if the mouse moves away from the side
84 // toolbar (as long as the timeout has elapsed). 85 // toolbar (as long as the timeout has elapsed).
85 if (!this.isMouseNearSideToolbar_ && !this.sideToolbarAllowedOnlyTimer_) 86 if (!this.isMouseNearSideToolbar_ && !this.sideToolbarAllowedOnlyTimer_)
86 this.sideToolbarAllowedOnly_ = false; 87 this.sideToolbarAllowedOnly_ = false;
87 88
88 // Allow the top toolbar to be shown if the mouse moves to the top edge. 89 // Allow the top toolbar to be shown if the mouse moves to the top edge.
89 if (this.isMouseNearTopToolbar_) 90 if (this.isMouseNearTopToolbar_)
90 this.sideToolbarAllowedOnly_ = false; 91 this.sideToolbarAllowedOnly_ = false;
91 92
92 // Show the toolbars if the mouse is near the top or right of the screen or 93 // Show the toolbars if the mouse is near the top or right of the screen or
93 // if the mouse moved fast. 94 // if the mouse moved fast.
94 if (this.isMouseNearTopToolbar_ || this.isMouseNearSideToolbar_ || 95 if (this.isMouseNearTopToolbar_ || this.isMouseNearSideToolbar_ ||
95 isHighVelocityMouseMove(e)) { 96 isHighVelocityMouseMove(e)) {
96 if (this.sideToolbarAllowedOnly_) 97 if (this.sideToolbarAllowedOnly_)
97 this.zoomToolbar_.show(); 98 this.zoomToolbar_.show();
98 else 99 else
99 this.showToolbars(); 100 this.showToolbars();
100 } 101 }
101 this.hideToolbarsAfterTimeout(); 102 this.hideToolbarsAfterTimeout();
102 }, 103 },
103 104
104 /** 105 /**
105 * Display both UI toolbars. 106 * Display both UI toolbars.
106 */ 107 */
107 showToolbars: function() { 108 showToolbars: function() {
108 this.toolbar_.show(); 109 if (this.toolbar_)
110 this.toolbar_.show();
109 this.zoomToolbar_.show(); 111 this.zoomToolbar_.show();
110 }, 112 },
111 113
112 /** 114 /**
113 * Check if the toolbars are able to be closed, and close them if they are. 115 * Check if the toolbars are able to be closed, and close them if they are.
114 * Toolbars may be kept open based on mouse/keyboard activity and active 116 * Toolbars may be kept open based on mouse/keyboard activity and active
115 * elements. 117 * elements.
116 */ 118 */
117 hideToolbarsIfAllowed: function() { 119 hideToolbarsIfAllowed: function() {
118 if (!(this.isMouseNearTopToolbar_ || this.isMouseNearSideToolbar_ || 120 if (this.isMouseNearSideToolbar_ || this.isMouseNearTopToolbar_)
119 this.toolbar_.shouldKeepOpen())) { 121 return;
122
123 if (this.toolbar_ && this.toolbar_.shouldKeepOpen())
124 return;
125
126 if (this.toolbar_)
120 this.toolbar_.hide(); 127 this.toolbar_.hide();
121 this.zoomToolbar_.hide(); 128 this.zoomToolbar_.hide();
122 }
123 }, 129 },
124 130
125 /** 131 /**
126 * Hide the toolbar after the HIDE_TIMEOUT has elapsed. 132 * Hide the toolbar after the HIDE_TIMEOUT has elapsed.
127 */ 133 */
128 hideToolbarsAfterTimeout: function() { 134 hideToolbarsAfterTimeout: function() {
129 if (this.toolbarTimeout_) 135 if (this.toolbarTimeout_)
130 clearTimeout(this.toolbarTimeout_); 136 clearTimeout(this.toolbarTimeout_);
131 this.toolbarTimeout_ = 137 this.toolbarTimeout_ =
132 setTimeout(this.hideToolbarsIfAllowed.bind(this), HIDE_TIMEOUT); 138 setTimeout(this.hideToolbarsIfAllowed.bind(this), HIDE_TIMEOUT);
133 }, 139 },
134 140
135 /** 141 /**
136 * Hide the 'topmost' layer of toolbars. Hides any dropdowns that are open, or 142 * Hide the 'topmost' layer of toolbars. Hides any dropdowns that are open, or
137 * hides the basic toolbars otherwise. 143 * hides the basic toolbars otherwise.
138 */ 144 */
139 hideSingleToolbarLayer: function() { 145 hideSingleToolbarLayer: function() {
140 if (!this.toolbar_.hideDropdowns()) 146 if (!this.toolbar_ || !this.toolbar_.hideDropdowns())
141 this.hideToolbarsIfAllowed(); 147 this.hideToolbarsIfAllowed();
142 }, 148 },
143 149
144 /** 150 /**
145 * Hide the top toolbar and keep it hidden until both: 151 * Hide the top toolbar and keep it hidden until both:
146 * - The mouse is moved away from the right side of the screen 152 * - The mouse is moved away from the right side of the screen
147 * - 1 second has passed. 153 * - 1 second has passed.
148 * 154 *
149 * The top toolbar can be immediately re-opened by moving the mouse to the top 155 * The top toolbar can be immediately re-opened by moving the mouse to the top
150 * of the screen. 156 * of the screen.
151 */ 157 */
152 forceHideTopToolbar: function() { 158 forceHideTopToolbar: function() {
159 if (!this.toolbar_)
160 return;
153 this.toolbar_.hide(); 161 this.toolbar_.hide();
154 this.sideToolbarAllowedOnly_ = true; 162 this.sideToolbarAllowedOnly_ = true;
155 this.sideToolbarAllowedOnlyTimer_ = this.window_.setTimeout(function() { 163 this.sideToolbarAllowedOnlyTimer_ = this.window_.setTimeout(function() {
156 this.sideToolbarAllowedOnlyTimer_ = null; 164 this.sideToolbarAllowedOnlyTimer_ = null;
157 }.bind(this), FORCE_HIDE_TIMEOUT); 165 }.bind(this), FORCE_HIDE_TIMEOUT);
158 }, 166 },
159 167
160 /** 168 /**
161 * Updates the size of toolbar dropdowns based on the positions of the rest of 169 * Updates the size of toolbar dropdowns based on the positions of the rest of
162 * the UI. 170 * the UI.
163 * @private 171 * @private
164 */ 172 */
165 resizeDropdowns_: function() { 173 resizeDropdowns_: function() {
174 if (!this.toolbar_)
175 return;
166 var lowerBound = this.window_.innerHeight - this.zoomToolbar_.clientHeight; 176 var lowerBound = this.window_.innerHeight - this.zoomToolbar_.clientHeight;
167 this.toolbar_.setDropdownLowerBound(lowerBound); 177 this.toolbar_.setDropdownLowerBound(lowerBound);
168 } 178 }
169 }; 179 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698