Fix patches that I generated poorly, and lost functionality.
[webos-internals:modifications.git] / browser / enable-browser-downloads.patch
1 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/chrome.js b/usr/palm/applications/com.palm.app.browser/app/controllers/chrome.js
2 index 4e0f974..fc1520d 100644
3 --- a/usr/palm/applications/com.palm.app.browser/app/controllers/chrome.js
4 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/chrome.js
5 @@ -102,12 +102,39 @@ Chrome.prototype._hidePortrait = function() {
6         }
7  };
8  
9 +Chrome.prototype.show = UrlBar.prototype._showNoOp;
10 +Chrome.prototype.hide = UrlBar.prototype._hideNoOp;
11 +
12  Chrome.prototype._showNoOp = function() {
13         // DO NOTHING - We don't show anything in landscape.    
14 +       var animator;
15 +       var element = this.controller.get(this._elementName);
16 +       
17 +       // If we are visible then the current spacer height is 
18 +       if (element && (this._currentHeight === 0)) {
19 +               animator = Mojo.Animation.animateStyle(element, 'height', 'linear', {
20 +                       from: 0,
21 +                       to: this._maxHeight,
22 +                       duration: 0.15,
23 +                       reverse: false
24 +               });
25 +               this._currentHeight = this._maxHeight;
26 +       }
27  };
28  
29  Chrome.prototype._hideNoOp = function() {
30         // DO NOTHING - We should not be displayed in landscape.
31 +       var animator;
32 +       var element = this.controller.get(this._elementName);
33 +       if (element && (this._currentHeight > 0)) {
34 +               animator = Mojo.Animation.animateStyle(element, 'height', 'linear', {
35 +                       from: 0,
36 +                       to: this._maxHeight,
37 +                       duration: 0.15,
38 +                       reverse: true
39 +               });
40 +               this._currentHeight = 0;
41 +       }
42  };
43  
44  Chrome.prototype.isVisible = function() {
45 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js b/usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js
46 new file mode 100644
47 index 0000000..4c07986
48 --- /dev/null
49 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/downloaddialog-assistant.js
50 @@ -0,0 +1,46 @@
51 +/**
52 + * A dialog assistant for display of yes/no box.
53 + */
54 +DownloadDialogAssistant = Class.create({
55 +
56 +        initialize: function(params) {
57 +                this.onDismiss = params.onDismiss;
58 +                this.onAccept = params.onAccept;
59 +                this.controller= params.sceneAssistant.controller;
60 +
61 +                // Button handlers.
62 +                this.onDismissHandler = this.handleDismiss.bindAsEventListener(this);
63 +                this.onAcceptHandler = this.handleAccept.bindAsEventListener(this);
64 +        },
65 +
66 +        setup: function(widget) {
67 +                this.widget = widget;
68 +                this.controller.get('acceptButton').addEventListener(Mojo.Event.tap, this.onAcceptHandler);
69 +                this.controller.get('acceptButton').focus();
70 +                this.controller.get('dismissButton').addEventListener(Mojo.Event.tap, this.onDismissHandler);
71 +                this.controller.get('dismissButton').focus();
72 +        },
73 +
74 +        handleDismiss: function() {
75 +                this.onDismiss();
76 +                delete this.onDismiss;
77 +                this.widget.mojo.close();
78 +        },
79 +        handleAccept: function() {
80 +                this.onAccept();
81 +                delete this.onAccept;
82 +                                delete this.onDismiss;
83 +                this.widget.mojo.close();
84 +        },
85 +
86 +        cleanup: function() {
87 +                Mojo.Log.info("NetworkDialogAssistant#cleanup()");
88 +                Mojo.Event.stopListening(this.controller.get('dismissButton'), Mojo.Event.tap, this.onDismissHandler);
89 +                Mojo.Event.stopListening(this.controller.get('acceptButton'), Mojo.Event.tap, this.onAcceptHandler);
90 +
91 +                // Send a dismiss if NOT already sent a response
92 +                if (this.onDismiss) {
93 +                        this.onDismiss();
94 +                }
95 +        }
96 +});
97 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/page-assistant.js b/usr/palm/applications/com.palm.app.browser/app/controllers/page-assistant.js
98 index a805d2c..1074480 100644
99 --- a/usr/palm/applications/com.palm.app.browser/app/controllers/page-assistant.js
100 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/page-assistant.js
101 @@ -1198,7 +1198,95 @@ PageAssistant.prototype._newBrowserPage = function(url, pageIdentifier){
102  PageAssistant.prototype._streamResource = function(uri, appid, mimeType){
103  
104         Mojo.Log.info("Streaming: '%s' with '%s' (%s)", uri, appid, mimeType);
105 -
106 +       if(appid === 'com.palm.app.email')
107 +       {
108 +           //an email was clicked, so we bypass the download dialog and open the email app.
109 +           var params = {target: uri, mimeType: mimeType};
110 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
111 +               method: 'open',
112 +               parameters: {
113 +                   'id': appid,
114 +                   'params': params
115 +               }}
116 +           );
117 +           return;
118 +       }
119 +                       if(appid === 'com.palm.app.docviwer')
120 +       {
121 +           //a doc was clicked, so we bypass the download dialog and open the docviewer app.
122 +           var params = {target: uri, mimeType: mimeType};
123 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
124 +               method: 'open',
125 +               parameters: {
126 +                   'id': appid,
127 +                   'params': params
128 +               }}
129 +           );
130 +           return;
131 +       }
132 +                       if(appid === 'com.palm.app.pdfviewer')
133 +       {
134 +           //a pdf was clicked, so we bypass the download dialog and open the pdfviewer app.
135 +           var params = {target: uri, mimeType: mimeType};
136 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
137 +               method: 'open',
138 +               parameters: {
139 +                   'id': appid,
140 +                   'params': params
141 +               }}
142 +           );
143 +           return;
144 +       }
145 +                       if(appid === 'com.palm.app.maps')
146 +       {
147 +           //a map was clicked, so we bypass the download dialog and open the maps app.
148 +           var params = {target: uri, mimeType: mimeType};
149 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
150 +               method: 'open',
151 +               parameters: {
152 +                   'id': appid,
153 +                   'params': params
154 +               }}
155 +           );
156 +           return;
157 +       }
158 +                       if(appid === 'com.palm.app.youtube')
159 +                       {
160 +           //a youtube video was clicked, so we bypass the download dialog and open the youtube app.
161 +           var params = {target: uri, mimeType: mimeType};
162 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
163 +               method: 'open',
164 +               parameters: {
165 +                   'id': appid,
166 +                   'params': params
167 +               }}
168 +           );
169 +           return;
170 +       }
171 +                       if(appid === 'com.palm.app.phone')
172 +       {               
173 +           //a phone # was clicked, so we bypass the download dialog and open the phone app.
174 +           var params = {target: uri, mimeType: mimeType};
175 +           this.controller.serviceRequest('palm://com.palm.applicationManager',{
176 +               method: 'open',
177 +               parameters: {
178 +                   'id': appid,
179 +                   'params': params
180 +               }}
181 +           );
182 +           return;
183 +       }
184 +           this._downloadWidgetElement = this.controller.showDialog({
185 +               uri: uri,
186 +               mimeType: mimeType,
187 +               appid: appid,
188 +               template: 'download/download-stream-popup',
189 +               assistant: new DownloadDialogAssistant({
190 +               sceneAssistant: this,
191 +               onDismiss: function(cParams) { // DOWNLOAD
192 +                       this._downloadResource(uri);
193 +               }.bind(this),
194 +               onAccept: function(cParams) { // STREAM
195         // Only a few select applications can be
196         crossAppScene = {
197                 'com.palm.app.videoplayer': 'nowplaying',
198 @@ -1206,11 +1294,9 @@ PageAssistant.prototype._streamResource = function(uri, appid, mimeType){
199         };
200         var params = {target: uri, mimeType: mimeType};
201         if (crossAppScene[appid]) {
202 -
203                 var args = { appId: appid, name: crossAppScene[appid] };
204                 this.controller.stageController.pushScene(args, params);
205 -       }
206 -       else {
207 +                       } else {
208                 this.controller.serviceRequest('palm://com.palm.applicationManager', {
209                         method: 'open',
210                         parameters: {
211 @@ -1219,6 +1305,9 @@ PageAssistant.prototype._streamResource = function(uri, appid, mimeType){
212                         }
213                 });
214         }
215 +               }.bind(this)})
216 +       });
217 +
218  };
219  
220  /**
221 @@ -2237,6 +2326,31 @@ PageAssistant.prototype._onKeyDownEvent = function(event) {
222                 // allowed to trigger the bar.
223                 if (this._addressBar.isAGotoAddressBarEvent(event.originalEvent)) {
224                         this._gotoUrlBar();
225 +               } else {
226 +                       var key = event.originalEvent.keyCode;
227 +                       var scroller = this.controller.getSceneScroller();
228 +                       var pageHeight = scroller.mojo.scrollerSize().height;
229 +                       if (pageHeight > 50) pageHeight = pageHeight - 50;
230 +                       if (key == 32) {
231 +                               // alternate method for scrolling, gives visual feedback, but slower
232 +                               //var currentTop = scroller.mojo.getScrollPosition().top;
233 +                               //currentTop += scroller.mojo.scrollerSize().height - 50;
234 +                               //scroller.mojo.scrollTo(undefined, currentTop, true);
235 +                               scroller.mojo.adjustBy(0, -1*pageHeight);
236 +                               this._addressBar.hide();
237 +                       } else if (key == 0) {
238 +                               scroller.mojo.adjustBy(0, pageHeight);
239 +                       } else if (key == 190) {
240 +                               scroller.mojo.adjustBy(0, -25);
241 +                               this._addressBar.hide();
242 +                       } else if (key == 8) {
243 +                               scroller.mojo.revealTop(0);
244 +                       } else if (key == 13) {
245 +                               scroller.mojo.revealBottom(0);
246 +                               this._addressBar.hide();
247 +                       } else {
248 +                               Mojo.Log.error("Ignoring keyCode", key);
249 +                       }
250                 }
251         }
252  };
253 diff --git a/usr/palm/applications/com.palm.app.browser/app/controllers/urlbar.js b/usr/palm/applications/com.palm.app.browser/app/controllers/urlbar.js
254 index 94abd5d..cafa2e4 100644
255 --- a/usr/palm/applications/com.palm.app.browser/app/controllers/urlbar.js
256 +++ b/usr/palm/applications/com.palm.app.browser/app/controllers/urlbar.js
257 @@ -47,6 +47,10 @@ UrlBar.prototype.setOrientation = function(orientation) {
258         if (orientation !== 'up') {
259                 // In landscape and down we ALWAYS hide the BAR so we make sure it's
260                 // already hidden by calling' 'hide'.
261 +               this.show = this._showNoOp;
262 +               this.hide = this._hideNoOp;
263 +       } else {
264 +               // Default is portrait.
265                 this._hidePortrait();
266         }
267  
268 @@ -73,6 +77,12 @@ UrlBar.prototype.setup = function(properties) {
269         this._onPropertyChange = properties.onPropertyChange || function(){};
270         this._configOrientation(properties.orientation || 'up');
271  
272 +       if (properties.orientation === 'up') {                               
273 +               this.owidth = 271;                                                
274 +       } else {                                                             
275 +               this.owidth = 430;                                                
276 +        }
277 +
278         this.models = {
279                 urlInput: {
280                         template: 'page/url-field',
281 @@ -90,7 +100,7 @@ UrlBar.prototype.setup = function(properties) {
282                                 url: ''
283                         },
284  
285 -                       width: 271
286 +                       width: this.owidth
287                 },
288  
289                 // Beware: These are shallow copies.
290 @@ -416,12 +426,25 @@ UrlBar.prototype._hidePortrait = function() {
291         this.controller.setMenuVisible(Mojo.Menu.viewMenu, false);
292  };
293  
294 +UrlBar.prototype.show = UrlBar.prototype._showNoOp;
295 +UrlBar.prototype.hide = UrlBar.prototype._hideNoOp;
296 +
297  UrlBar.prototype._showNoOp = function() {
298         // DO NOTHING - We don't show anything in landscape.
299 +       var menuAssistant = this.controller._menu.assistant;
300 +       var spacerHeight = menuAssistant.viewSpacerHeight;
301 +       
302 +       menuAssistant.viewSpacerHeight = 0;
303 +       this.controller.setMenuVisible(Mojo.Menu.viewMenu, true);
304  };
305  
306  UrlBar.prototype._hideNoOp = function() {
307         // DO NOTHING - We should not be displayed in landscape.
308 +       var menuAssistant = this.controller._menu.assistant;
309 +       var spacerHeight = menuAssistant.viewSpacerHeight;
310 +       
311 +       menuAssistant.viewSpacerHeight = 0;
312 +       this.controller.setMenuVisible(Mojo.Menu.viewMenu, false);
313  };
314  
315  UrlBar.prototype.isVisible = function() {
316 diff --git a/usr/palm/applications/com.palm.app.browser/app/views/download/download-stream-popup.html b/usr/palm/applications/com.palm.app.browser/app/views/download/download-stream-popup.html
317 new file mode 100644
318 index 0000000..b705ece
319 --- /dev/null
320 +++ b/usr/palm/applications/com.palm.app.browser/app/views/download/download-stream-popup.html
321 @@ -0,0 +1,8 @@
322 +<div id="palm-dialog-content" class="palm-dialog-content">
323 +        <div class="dialog-message" x-mojo-loc="">This file type has been registered as a streaming media file. Would you like to download it to /media/internal/downloads instead?</div>
324 +</div>
325 +
326 +<div class="palm-dialog-buttons">
327 +        <div class="dismiss palm-button" id="acceptButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Stream</div>
328 +        <div class="dismiss palm-button" id="dismissButton" x-mojo-loc="" x-mojo-tap-highlight="momentary">Download</div>
329 +</div>
330 diff --git a/usr/palm/applications/com.palm.app.browser/sources.json b/usr/palm/applications/com.palm.app.browser/sources.json
331 index 54187ce..7d79e70 100644
332 --- a/usr/palm/applications/com.palm.app.browser/sources.json
333 +++ b/usr/palm/applications/com.palm.app.browser/sources.json
334 @@ -48,6 +48,9 @@
335         "source": "app\/controllers\/download-controller.js",
336    },
337    {  
338 +       "source":"app\/controllers\/downloaddialog-assistant.js"
339 +  },
340 +  {  
341         "source": "app\/controllers\/preferences-assistant.js",
342    },
343    {
344 diff --git a/usr/palm/applications/com.palm.app.browser/stylesheets/browser.css b/usr/palm/applications/com.palm.app.browser/stylesheets/browser.css
345 index 6215e0b..aee8654 100644
346 --- a/usr/palm/applications/com.palm.app.browser/stylesheets/browser.css
347 +++ b/usr/palm/applications/com.palm.app.browser/stylesheets/browser.css
348 @@ -753,7 +753,7 @@ div#historyScroller {
349  }
350  
351  .search-results-container .palm-list {
352 -       width: 304px;
353 +       width: 95%;
354  }
355  
356  .search-results-container .search.first {