|
1 /* |
|
2 * This file is part of the popup menu implementation for <select> elements in WebCore. |
|
3 * |
|
4 * Copyright (C) 2006 Apple Computer, Inc. |
|
5 * Copyright (C) 2007 Nokia Inc. |
|
6 * |
|
7 * This library is free software; you can redistribute it and/or |
|
8 * modify it under the terms of the GNU Library General Public |
|
9 * License as published by the Free Software Foundation; either |
|
10 * version 2 of the License, or (at your option) any later version. |
|
11 * |
|
12 * This library is distributed in the hope that it will be useful, |
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
15 * Library General Public License for more details. |
|
16 * |
|
17 * You should have received a copy of the GNU Library General Public License |
|
18 * along with this library; see the file COPYING.LIB. If not, write to |
|
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
|
20 * Boston, MA 02111-1307, USA. |
|
21 */ |
|
22 |
|
23 #include "config.h" |
|
24 #include "../../bidi.h" |
|
25 #include "PopupMenu.h" |
|
26 |
|
27 #include "Frame.h" |
|
28 #include "Page.h" |
|
29 #include "FrameLoader.h" |
|
30 #include "FrameView.h" |
|
31 #include "RenderMenuList.h" |
|
32 #include "WebFrame.h" |
|
33 #include "WebView.h" |
|
34 #include "brctl.h" |
|
35 |
|
36 #include <e32base.h> |
|
37 #include <BrCtlDialogsProvider.h> |
|
38 |
|
39 namespace WebCore { |
|
40 |
|
41 static void ResetAndDestroy(TAny *aPtr); |
|
42 PopupMenu::PopupMenu(PopupMenuClient* client) : m_popupClient(client) |
|
43 { |
|
44 } |
|
45 void ResetAndDestroy(TAny *aPtr) |
|
46 { |
|
47 RPointerArray<HBufC>* items = (RPointerArray<HBufC>*) aPtr; |
|
48 items->ResetAndDestroy(); |
|
49 } |
|
50 void PopupMenu::show(const IntRect&, FrameView* v, int index) |
|
51 { |
|
52 TRAP_IGNORE(showL(v, index)); |
|
53 } |
|
54 |
|
55 void PopupMenu::showL(FrameView* v, int index) |
|
56 { |
|
57 if (v->frame()->page()->mainFrame()->loader()->provisionalDocumentLoader()) { |
|
58 return; |
|
59 } |
|
60 WebView* wv = kit(v->frame()->page()); |
|
61 MBrCtlDialogsProvider* dialogs = wv->brCtl()->brCtlDialogsProvider(); |
|
62 int size = client()->listSize(); |
|
63 CArrayFix<TBrCtlSelectOptionData>* options = new CArrayFixFlat<TBrCtlSelectOptionData>(size); |
|
64 RPointerArray<HBufC> items(size); |
|
65 CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&items)); |
|
66 |
|
67 for (int i = 0; i < size; i++) { |
|
68 // better separator |
|
69 if (client()->itemIsSeparator(i)) { |
|
70 TBrCtlSelectOptionData data(_L("----------"), false, false, false); |
|
71 options->AppendL(data); |
|
72 } |
|
73 else { |
|
74 HBufC16* itemStr = client()->itemText(i).des().AllocL(); |
|
75 CleanupStack::PushL(itemStr); |
|
76 if (itemStr != NULL) { |
|
77 TBrCtlSelectOptionData data(*itemStr, i==client()->selectedIndex(), false, client()->itemIsEnabled(i)); |
|
78 options->AppendL(data); |
|
79 items.AppendL(itemStr); |
|
80 } |
|
81 CleanupStack::Pop(); |
|
82 } |
|
83 } |
|
84 |
|
85 dialogs->DialogSelectOptionL(KNullDesC(), ESelectTypeSingle, *options); |
|
86 int newIndex = index; |
|
87 CleanupStack::PopAndDestroy(&items); |
|
88 |
|
89 int count = options->Count(); |
|
90 for (newIndex = 0 ; newIndex < count && !options->At(newIndex).IsSelected(); newIndex++) {} |
|
91 if (newIndex == count) { |
|
92 newIndex = index; |
|
93 } |
|
94 m_popupClient->hidePopup(); |
|
95 |
|
96 if (index != newIndex && newIndex >= 0) { |
|
97 m_popupClient->valueChanged(newIndex); |
|
98 } |
|
99 delete options; |
|
100 |
|
101 } |
|
102 |
|
103 void PopupMenu::hide() |
|
104 { |
|
105 // impossible |
|
106 } |
|
107 |
|
108 bool PopupMenu::itemWritingDirectionIsNatural() |
|
109 { |
|
110 return true; |
|
111 } |
|
112 |
|
113 // PopupMenu |
|
114 void PopupMenu::updateFromElement() |
|
115 { |
|
116 } |
|
117 |
|
118 PopupMenu::~PopupMenu() |
|
119 { |
|
120 |
|
121 } |
|
122 |
|
123 |
|
124 } |