|
1 /* |
|
2 * Copyright (c) 2002-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * Implementation of CBrowserBookmarksContainer. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 |
|
23 #include <AknViewAppUi.h> |
|
24 #include <aknsfld.h> |
|
25 #include <BrowserNG.rsg> |
|
26 #include <FavouritesItem.h> |
|
27 #include <FeatMgr.h> |
|
28 |
|
29 #include "CommonConstants.h" |
|
30 #include "BrowserFavouritesView.h" |
|
31 #include "BrowserBookmarksContainer.h" |
|
32 #include "BrowserBookmarksGotoPane.h" |
|
33 #include "BrowserFavouritesListbox.h" |
|
34 #include "BrowserUtil.h" |
|
35 #include "BrowserAppUi.h" |
|
36 #include "BrowserBookmarksListboxIconHandler.h" |
|
37 #ifdef __SERIES60_HELP |
|
38 // Context-Sensitve Help File |
|
39 #include "BrowserApplication.h" |
|
40 #include <csxhelp/browser.hlp.hrh> |
|
41 #endif // __SERIES60_HELP |
|
42 #include "Logger.h" |
|
43 #include "e32event.h" |
|
44 |
|
45 // CONSTANTS |
|
46 |
|
47 /// Tab index for Bookmarks View. |
|
48 LOCAL_D const TInt KBookmarkTabIndex = 0; |
|
49 |
|
50 // ================= MEMBER FUNCTIONS ======================= |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // CBrowserBookmarksContainer::NewL |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CBrowserBookmarksContainer* CBrowserBookmarksContainer::NewL( |
|
57 const TRect& aRect, |
|
58 CBrowserFavouritesView& aView) |
|
59 { |
|
60 CBrowserBookmarksContainer* container = |
|
61 new (ELeave) CBrowserBookmarksContainer; |
|
62 CleanupStack::PushL( container ); |
|
63 container->ConstructL( aRect, aView ); |
|
64 CleanupStack::Pop(); // container |
|
65 return container; |
|
66 } |
|
67 |
|
68 // --------------------------------------------------------- |
|
69 // CBrowserBookmarksContainer::~CBrowserBookmarksContainer |
|
70 // --------------------------------------------------------- |
|
71 // |
|
72 CBrowserBookmarksContainer::~CBrowserBookmarksContainer() |
|
73 { |
|
74 delete iGotoPane; |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------- |
|
78 // CBrowserBookmarksContainer::SetGotoActiveL |
|
79 // --------------------------------------------------------- |
|
80 // |
|
81 void CBrowserBookmarksContainer::SetGotoActiveL() |
|
82 { |
|
83 if( !iGotoPaneActive) |
|
84 { |
|
85 iGotoPaneActive = ETrue; |
|
86 |
|
87 Listbox()->UpdateFilterL(); |
|
88 |
|
89 // redraw |
|
90 SizeChanged(); |
|
91 |
|
92 iGotoPane->BeginEditingL(); |
|
93 |
|
94 DrawDeferred(); |
|
95 } |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------- |
|
100 // CBrowserBookmarksContainer::SetGotoInactiveL(); |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 |
|
104 void CBrowserBookmarksContainer::SetGotoInactiveL() |
|
105 { |
|
106 if(iGotoPaneActive) |
|
107 { |
|
108 iGotoPaneActive = EFalse; |
|
109 |
|
110 // Deactivate GoTo Pane |
|
111 iGotoPane->MakeVisible( EFalse ); |
|
112 iGotoPane->CancelEditingL(); |
|
113 iGotoPane->SetFocus( EFalse ); |
|
114 |
|
115 // redraw |
|
116 Listbox()->UpdateFilterL(); |
|
117 SizeChanged(); |
|
118 DrawDeferred(); |
|
119 } |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------- |
|
123 // CBrowserBookmarksContainer::CountComponentControls |
|
124 // --------------------------------------------------------- |
|
125 // |
|
126 TInt CBrowserBookmarksContainer::CountComponentControls() const |
|
127 { |
|
128 return (Listbox() ? 1 : 0) + (iGotoPane ? 1 : 0); |
|
129 } |
|
130 |
|
131 // --------------------------------------------------------- |
|
132 // CBrowserBookmarksContainer::ComponentControl |
|
133 // --------------------------------------------------------- |
|
134 // |
|
135 CCoeControl* CBrowserBookmarksContainer::ComponentControl |
|
136 ( TInt aIndex ) const |
|
137 { |
|
138 switch (aIndex) |
|
139 { |
|
140 case 0: |
|
141 { |
|
142 return Listbox(); |
|
143 } |
|
144 |
|
145 case 1: |
|
146 { |
|
147 return iGotoPane; |
|
148 } |
|
149 |
|
150 default: |
|
151 { |
|
152 return NULL; |
|
153 } |
|
154 } |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------- |
|
158 // CBrowserBookmarksContainer::SizeChanged |
|
159 // --------------------------------------------------------- |
|
160 // |
|
161 void CBrowserBookmarksContainer::SizeChanged() |
|
162 { |
|
163 TRect rect = Rect(); |
|
164 TInt unfilteredNumberOfItems = Listbox()->UnfilteredNumberOfItems(); |
|
165 |
|
166 // if goto pane is active |
|
167 if( iGotoPaneActive ) |
|
168 { |
|
169 // Enable / disable line in Goto Pane (hide if listbox is empty). |
|
170 iGotoPane->SetLineState( unfilteredNumberOfItems > 0 ); |
|
171 |
|
172 // In Goto Mode, the listbox is laid out leaving space for Goto Pane. |
|
173 AknLayoutUtils::LayoutControl( Listbox(), rect, AknLayout::list_gen_pane( 1 )); |
|
174 |
|
175 // Lay out Goto Pane as if it was the old Find Pane. |
|
176 AknLayoutUtils::LayoutControl( iGotoPane, rect, AknLayout::find_pane() ); |
|
177 } |
|
178 else |
|
179 { |
|
180 // Fall back upon default behavior in base-class, which lays out the bookmarks list only |
|
181 CBrowserFavouritesContainer::SizeChanged(); |
|
182 } |
|
183 } |
|
184 |
|
185 // --------------------------------------------------------- |
|
186 // CBrowserBookmarksContainer::OfferKeyEventL |
|
187 // --------------------------------------------------------- |
|
188 // |
|
189 TKeyResponse CBrowserBookmarksContainer::OfferKeyEventL |
|
190 ( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
191 { |
|
192 /* |
|
193 LOG_ENTERFN( "BookmarksContainer::OfferKeyEventL" ); |
|
194 BROWSER_LOG( ( _L("aType: %d, aKeyEvent.iCode: %d, iScanCode: %d, iRepeats: %d"), |
|
195 aType, aKeyEvent.iCode, aKeyEvent.iScanCode, aKeyEvent.iRepeats ) ); |
|
196 */ |
|
197 TKeyResponse result = EKeyWasNotConsumed; |
|
198 TKeyEvent keyEvent( aKeyEvent ); |
|
199 |
|
200 // Selection Key handling |
|
201 if( keyEvent.iScanCode == EStdKeyDevice3 ) |
|
202 { |
|
203 // it is possible to activate BookmarksView from ContentView |
|
204 // via a long press of Selection key, so here we must capture |
|
205 // the KeyDown. Long press processing will be done only if key |
|
206 // was pressed originally in this view. |
|
207 if( aType == EEventKeyDown ) |
|
208 { |
|
209 iSelectionKeyDownPressed = ETrue; |
|
210 result = EKeyWasConsumed; |
|
211 } |
|
212 else if( aType == EEventKeyUp ) |
|
213 { |
|
214 if( !iSelectionKeyLongPress && iSelectionKeyDownPressed ) |
|
215 { |
|
216 // short press of Selection key, pass it to GotoPane |
|
217 keyEvent.iCode = EKeyOK; |
|
218 result = EKeyWasNotConsumed; |
|
219 } |
|
220 else |
|
221 { |
|
222 // long press of Selection key was already processed |
|
223 result = EKeyWasConsumed; |
|
224 } |
|
225 iSelectionKeyDownPressed = EFalse; |
|
226 iSelectionKeyLongPress = EFalse; |
|
227 } |
|
228 else if( aType == EEventKey ) |
|
229 { |
|
230 if( keyEvent.iRepeats && iSelectionKeyDownPressed ) |
|
231 { |
|
232 const CFavouritesItem* item = Listbox()->CurrentItem(); |
|
233 if ( item ) |
|
234 { |
|
235 // The option for the user to download the page in new window is disabled |
|
236 CBrowserAppUi::Static()->FetchBookmarkL( *item ); |
|
237 } |
|
238 iSelectionKeyLongPress = ETrue; |
|
239 iSelectionKeyDownPressed = EFalse; |
|
240 } |
|
241 |
|
242 if ( (aKeyEvent.iScanCode == EStdKeyHash) || |
|
243 ( aKeyEvent.iModifiers & |
|
244 ( EModifierShift | EModifierLeftShift | EModifierRightShift | |
|
245 EModifierCtrl | EModifierLeftCtrl | EModifierRightCtrl ) ) ) |
|
246 { |
|
247 |
|
248 // Hash key press will be used for Mark/UnMark functionality |
|
249 // Let Platform Listbox handle this. |
|
250 result = EKeyWasNotConsumed; |
|
251 } |
|
252 else |
|
253 { |
|
254 result = EKeyWasConsumed; |
|
255 } |
|
256 } |
|
257 } |
|
258 // If the Goto Pane exists and we're not fetching, then decide |
|
259 // if we should pass keystroke to it |
|
260 if(iGotoPane) |
|
261 { |
|
262 // If the key so far hadn't been consumed or if the pane is already active, |
|
263 // pass the keystroke on |
|
264 if( (result == EKeyWasNotConsumed) || (iGotoPaneActive) ) |
|
265 { |
|
266 // Goto pane has highest priority; if it's active, arrow keys go there. |
|
267 // If fetching is in progress, no key events are offered, to prevent it |
|
268 // from getting the focus and popping up a new CBA. |
|
269 |
|
270 // Enter Key now handled through HandleCommand in BrowserBookmarksView like MSK |
|
271 // This change affects the enter key on the QWERTY keyboard when we run emulator |
|
272 if(EStdKeyEnter == aKeyEvent.iScanCode && EEventKeyUp == aType && AknLayoutUtils::MSKEnabled() && iGotoPaneActive ) |
|
273 { |
|
274 CEikButtonGroupContainer* myCba = CEikButtonGroupContainer::Current(); |
|
275 if(myCba != NULL) |
|
276 { |
|
277 TInt cmdId = myCba->ButtonGroup()->CommandId(CEikButtonGroupContainer::EMiddleSoftkeyPosition); |
|
278 View().HandleCommandL(cmdId); |
|
279 result = EKeyWasConsumed; |
|
280 } |
|
281 } |
|
282 else |
|
283 { |
|
284 result = iGotoPane->OfferKeyEventL( keyEvent, aType ); |
|
285 } |
|
286 |
|
287 // if key is consumed, goto pane was not active, make it active now. |
|
288 if(result == EKeyWasConsumed && |
|
289 !iGotoPaneActive) |
|
290 { |
|
291 SetGotoActiveL(); |
|
292 } |
|
293 } |
|
294 } |
|
295 // For handling Enter key in emulator / Keyboard ( Enter key should behave similar to MSK ) |
|
296 if(EStdKeyEnter == keyEvent.iScanCode && EEventKey == aType && AknLayoutUtils::MSKEnabled() && result == EKeyWasNotConsumed ) |
|
297 { |
|
298 CEikButtonGroupContainer* myCba = CEikButtonGroupContainer::Current(); |
|
299 if(myCba != NULL) |
|
300 { |
|
301 TInt cmdId = myCba->ButtonGroup()->CommandId(CEikButtonGroupContainer::EMiddleSoftkeyPosition); |
|
302 if(EAknSoftkeyContextOptions == cmdId) |
|
303 { |
|
304 View().MenuBar()->TryDisplayContextMenuBarL(); |
|
305 result = EKeyWasConsumed; |
|
306 } |
|
307 else if(Listbox()->Model()->ItemTextArray()->MdcaCount() == 0) |
|
308 { |
|
309 View().HandleCommandL(cmdId); |
|
310 result = EKeyWasConsumed; |
|
311 } |
|
312 } |
|
313 } |
|
314 |
|
315 if ( result == EKeyWasNotConsumed ) |
|
316 { |
|
317 // Otherwise, base class handles Find pane, arrows between folders and |
|
318 // the listbox. |
|
319 result = CBrowserFavouritesContainer::OfferKeyEventL |
|
320 ( keyEvent, aType ); |
|
321 } |
|
322 |
|
323 return result; |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------- |
|
327 // CBrowserBookmarksContainer::HandleCursorChangedL |
|
328 // --------------------------------------------------------- |
|
329 // |
|
330 void CBrowserBookmarksContainer::HandleCursorChangedL |
|
331 ( CEikListBox* |
|
332 #ifdef _DEBUG |
|
333 aListBox // used only for debugging purposes |
|
334 #endif |
|
335 ) |
|
336 { |
|
337 #ifdef _DEBUG |
|
338 __ASSERT_DEBUG( aListBox == Listbox(), |
|
339 Util::Panic( Util::EFavouritesBadListbox ) ); |
|
340 #endif |
|
341 |
|
342 if ( iGotoPane->IsVisible() ) |
|
343 { |
|
344 // Set Goto Pane text (URL or default http text) - this will cancel |
|
345 // Goto Pane editing. |
|
346 TPtrC url( KWWWString ); |
|
347 TBrowserFavouritesSelectionState selection = |
|
348 Listbox()->SelectionStateL(); |
|
349 if ( !selection.AnyMarked() && selection.CurrentIsItem() ) |
|
350 { |
|
351 // Exactly one item is selected. |
|
352 const CFavouritesItem* item = Listbox()->CurrentItem(); |
|
353 if ( item ) // Sanity check. |
|
354 { |
|
355 // If one item is highlighted, set to current URL. |
|
356 url.Set( Util::StripUrl( item->Url() ) ); |
|
357 } |
|
358 } |
|
359 iGotoPane->SetTextL( url, ETrue ); |
|
360 iGotoPane->SetFocus ( EFalse ); |
|
361 } |
|
362 } |
|
363 |
|
364 // --------------------------------------------------------- |
|
365 // CBrowserBookmarksContainer::IsEditing |
|
366 // --------------------------------------------------------- |
|
367 // |
|
368 TBool CBrowserBookmarksContainer::IsEditing() |
|
369 { |
|
370 TBool editing = EFalse; |
|
371 editing = iGotoPane->IsEditing(); |
|
372 return editing; |
|
373 } |
|
374 |
|
375 // --------------------------------------------------------- |
|
376 // CBrowserBookmarksContainer::TabIndex |
|
377 // --------------------------------------------------------- |
|
378 // |
|
379 TInt CBrowserBookmarksContainer::TabIndex() |
|
380 { |
|
381 return KBookmarkTabIndex; |
|
382 } |
|
383 |
|
384 // --------------------------------------------------------- |
|
385 // CBrowserBookmarksContainer::ListboxEmptyTextResourceId |
|
386 // --------------------------------------------------------- |
|
387 // |
|
388 TInt CBrowserBookmarksContainer::ListboxEmptyTextResourceId() |
|
389 { |
|
390 return R_BROWSER_BOOKMARKS_TEXT_NO_BOOKMARKS; |
|
391 } |
|
392 |
|
393 // --------------------------------------------------------- |
|
394 // CBrowserBookmarksContainer::TitleResourceId |
|
395 // --------------------------------------------------------- |
|
396 // |
|
397 TInt CBrowserBookmarksContainer::TitleResourceId() |
|
398 { |
|
399 return R_BROWSER_OPTION_BOOKMARKS; |
|
400 } |
|
401 |
|
402 // --------------------------------------------------------- |
|
403 // CBrowserBookmarksContainer::CBrowserBookmarksContainer |
|
404 // --------------------------------------------------------- |
|
405 // |
|
406 CBrowserBookmarksContainer::CBrowserBookmarksContainer() |
|
407 : iGotoPaneActive( EFalse ) |
|
408 { |
|
409 } |
|
410 |
|
411 // --------------------------------------------------------- |
|
412 // CBrowserBookmarksContainer::ConstructComponentControlsL |
|
413 // --------------------------------------------------------- |
|
414 // |
|
415 void CBrowserBookmarksContainer::ConstructComponentControlsL( |
|
416 const TRect& aRect, |
|
417 CBrowserFavouritesView& aView ) |
|
418 { |
|
419 CBrowserFavouritesContainer::ConstructComponentControlsL |
|
420 ( aRect, aView ); |
|
421 |
|
422 |
|
423 // Construct Goto Pane. |
|
424 |
|
425 //pass view to bookmarks goto pane |
|
426 iGotoPane = CBrowserBookmarksGotoPane::NewL( *this, &aView ); |
|
427 iGotoPane->SetFocus( EFalse ); |
|
428 } |
|
429 |
|
430 // --------------------------------------------------------- |
|
431 // CBrowserBookmarksContainer::CreateListboxIconHandlerL |
|
432 // --------------------------------------------------------- |
|
433 // |
|
434 MBrowserFavouritesListboxIconHandler* |
|
435 CBrowserBookmarksContainer::CreateListboxIconHandlerL() |
|
436 { |
|
437 return new (ELeave) TBrowserBookmarksListboxIconHandler; |
|
438 } |
|
439 |
|
440 #ifdef __SERIES60_HELP |
|
441 // --------------------------------------------------------- |
|
442 // CBrowserBookmarksContainer::GetHelpContext() |
|
443 // --------------------------------------------------------- |
|
444 // |
|
445 void CBrowserBookmarksContainer::GetHelpContext( TCoeHelpContext& aContext ) const |
|
446 { |
|
447 aContext.iMajor = KUidBrowserApplication; |
|
448 aContext.iContext = KOSS_HLP_BM_MAIN; |
|
449 } |
|
450 #endif // __SERIES60_HELP |
|
451 |
|
452 // --------------------------------------------------------- |
|
453 // CBrowserBookmarksContainer::FocusChanged() |
|
454 // --------------------------------------------------------- |
|
455 // |
|
456 void CBrowserBookmarksContainer::FocusChanged( TDrawNow aDrawNow ) |
|
457 { |
|
458 if ( IsEditing() ) |
|
459 { |
|
460 iGotoPane->SetFocus( IsFocused(), aDrawNow ); |
|
461 } |
|
462 else if ( Listbox() && Listbox()->IsVisible() ) |
|
463 { |
|
464 Listbox()->SetFocus( IsFocused(), aDrawNow ); |
|
465 } |
|
466 } |
|
467 |
|
468 // ---------------------------------------------------------------------------- |
|
469 // CBrowserBookmarksContainer::HandlePointerEventL |
|
470 // ---------------------------------------------------------------------------- |
|
471 // |
|
472 void CBrowserBookmarksContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
473 { |
|
474 if (AknLayoutUtils::PenEnabled()) |
|
475 { |
|
476 // if goto is active, if a pointer event falls within its rect, |
|
477 // pass all pointer events to it (such as, to bring up the editor's letter-entry) |
|
478 // |
|
479 // otherwise, if it falls within the listbox's rect |
|
480 // |
|
481 if (iGotoPaneActive && iGotoPane) |
|
482 { |
|
483 iGotoPane->HandlePointerEventL(aPointerEvent); |
|
484 } |
|
485 else |
|
486 { |
|
487 // normally, pass all pointer events down to the listbox |
|
488 Listbox()->HandlePointerEventL(aPointerEvent); |
|
489 } |
|
490 } |
|
491 } |
|
492 |
|
493 // End of File |