|
1 /* |
|
2 * Copyright (c) 2006 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "config.h" |
|
20 |
|
21 #include "RenderTheme.h" |
|
22 #include "Event.h" |
|
23 #include "Document.h" |
|
24 #include "Image.h" |
|
25 #include "GraphicsContext.h" |
|
26 #include <../bidi.h> |
|
27 #include <eikenv.h> |
|
28 #include "RenderBox.h" |
|
29 #include <BitmapTransforms.h> |
|
30 #include "WebCoreGraphicsContext.h" |
|
31 #include "MaskedBitmap.h" |
|
32 #include "BitmapImage.h" |
|
33 #include "WebCoreWidget.h" |
|
34 // implement Symbian theme here |
|
35 |
|
36 namespace WebCore { |
|
37 |
|
38 enum { |
|
39 ECheckBoxOn, |
|
40 ECheckBoxOff, |
|
41 ERadioOn, |
|
42 ERadioOff, |
|
43 ESelectArrow |
|
44 }; |
|
45 |
|
46 class RenderThemeSymbian : public RenderTheme |
|
47 { |
|
48 public: |
|
49 RenderThemeSymbian(); |
|
50 // A method asking if the theme's controls actually care about redrawing when hovered. |
|
51 bool supportsHover(const RenderStyle*) const { return true; } |
|
52 |
|
53 void setCheckboxSize(RenderStyle*) const; |
|
54 void setRadioSize(RenderStyle*) const; |
|
55 |
|
56 void adjustButtonStyle(CSSStyleSelector*, RenderStyle*, Element*) const; |
|
57 void adjustTextFieldStyle(CSSStyleSelector*, RenderStyle*, Element*) const; |
|
58 void adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const; |
|
59 void adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const; |
|
60 |
|
61 bool paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); |
|
62 bool paintButton(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); |
|
63 bool paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); |
|
64 bool paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); |
|
65 bool paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); |
|
66 bool paintTextField(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); |
|
67 bool paintTextArea(RenderObject*, const RenderObject::PaintInfo&, const IntRect&); |
|
68 |
|
69 |
|
70 bool isControlStyled(const RenderStyle*, const BorderData&, |
|
71 const BackgroundLayer&, const Color&) const; |
|
72 bool controlSupportsTints(const RenderObject*) const; |
|
73 void systemFont(int propId, FontDescription&) const; |
|
74 |
|
75 Color platformActiveSelectionBackgroundColor() const; |
|
76 Color platformInactiveSelectionBackgroundColor() const; |
|
77 Color platformActiveSelectionForegroundColor() const; |
|
78 Color platformInactiveSelectionForegroundColor() const; |
|
79 |
|
80 void addIntrinsicMargins(RenderStyle*) const; |
|
81 void close(); |
|
82 bool supportsFocus(EAppearance) const; |
|
83 void paintButtonDecorations(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r); |
|
84 |
|
85 bool supportsFocusRing(const RenderStyle*) const; |
|
86 void scaleImage(int type, int scalingFactor); |
|
87 void scaleImageL(int type, int scalingFactor); |
|
88 |
|
89 void cancel(); |
|
90 void run(); |
|
91 |
|
92 Image* m_checkBoxOn; |
|
93 Image* m_checkBoxOff; |
|
94 Image* m_scaledCheckBoxOn; |
|
95 Image* m_scaledCheckBoxOff; |
|
96 int m_scalingForCheckBoxOn; |
|
97 int m_scalingForCheckBoxOff; |
|
98 |
|
99 Image* m_radioButtonOn; |
|
100 Image* m_radioButtonOff; |
|
101 Image* m_scaledRadioOn; |
|
102 Image* m_scaledRadioOff; |
|
103 int m_scalingForRadioOn; |
|
104 int m_scalingForRadioOff; |
|
105 |
|
106 Image* m_selectArrow; |
|
107 Image* m_scaledSelectArrow; |
|
108 int m_scalingForSelectArrow; |
|
109 |
|
110 CBitmapScaler* m_bitmapScaler; |
|
111 CActiveSchedulerWait* m_asw; |
|
112 }; |
|
113 |
|
114 RenderTheme* theme() |
|
115 { |
|
116 static RenderThemeSymbian symbianTheme; |
|
117 return &symbianTheme; |
|
118 } |
|
119 |
|
120 MScrollView* scrollView(const RenderObject::PaintInfo& i) |
|
121 { |
|
122 return &(i.context->platformContext()->view()); |
|
123 } |
|
124 |
|
125 class SyncScaler : public CActive |
|
126 { |
|
127 public: |
|
128 SyncScaler(); |
|
129 ~SyncScaler(); |
|
130 void init(); |
|
131 void RunL(); |
|
132 void DoCancel(); |
|
133 TInt RunError(TInt aError); |
|
134 int m_error; |
|
135 }; |
|
136 |
|
137 SyncScaler::SyncScaler() : CActive (CActive::EPriorityHigh) |
|
138 { |
|
139 CActiveScheduler::Add(this); |
|
140 } |
|
141 |
|
142 SyncScaler::~SyncScaler() |
|
143 { |
|
144 Cancel(); |
|
145 } |
|
146 |
|
147 void SyncScaler::init() |
|
148 { |
|
149 m_error = KErrNone; |
|
150 iStatus = KRequestPending; |
|
151 SetActive(); |
|
152 } |
|
153 |
|
154 void SyncScaler::RunL() |
|
155 { |
|
156 m_error = iStatus.Int(); |
|
157 static_cast<RenderThemeSymbian*>(theme())->run(); |
|
158 } |
|
159 |
|
160 void SyncScaler::DoCancel() |
|
161 { |
|
162 // Since the operation is very fast, not sure what could cause it to be canceled. |
|
163 static_cast<RenderThemeSymbian*>(theme())->cancel(); |
|
164 } |
|
165 |
|
166 TInt SyncScaler::RunError(TInt aError) |
|
167 { |
|
168 m_error = aError; |
|
169 static_cast<RenderThemeSymbian*>(theme())->run(); |
|
170 return KErrNone; |
|
171 } |
|
172 |
|
173 RenderThemeSymbian::RenderThemeSymbian() |
|
174 { |
|
175 m_checkBoxOn = Image::loadPlatformResource("checkBoxOn"); |
|
176 m_checkBoxOff = Image::loadPlatformResource("checkBoxOff"); |
|
177 m_scaledCheckBoxOn = 0; |
|
178 m_scaledCheckBoxOff = 0; |
|
179 m_scalingForCheckBoxOn = 0; |
|
180 m_scalingForCheckBoxOff = 0; |
|
181 |
|
182 m_radioButtonOn = 0; |
|
183 m_radioButtonOff = 0; |
|
184 m_scaledRadioOn = 0; |
|
185 m_scaledRadioOff = 0; |
|
186 m_scalingForRadioOn = 0; |
|
187 m_scalingForRadioOff = 0; |
|
188 |
|
189 m_selectArrow = 0; |
|
190 m_scaledSelectArrow = 0; |
|
191 m_scalingForSelectArrow = 0; |
|
192 |
|
193 m_bitmapScaler = NULL; |
|
194 m_asw = NULL; |
|
195 } |
|
196 |
|
197 void RenderThemeSymbian::systemFont(int propId, FontDescription& fontDescription) const |
|
198 { |
|
199 } |
|
200 |
|
201 |
|
202 Color RenderThemeSymbian::platformActiveSelectionBackgroundColor() const |
|
203 { |
|
204 TRgb c = CEikonEnv::Static()->Color(EColorControlHighlightBackground); |
|
205 return Color(c.Red(),c.Green(),c.Blue()); |
|
206 } |
|
207 |
|
208 Color RenderThemeSymbian::platformInactiveSelectionBackgroundColor() const |
|
209 { |
|
210 return platformActiveSelectionBackgroundColor(); |
|
211 } |
|
212 |
|
213 Color RenderThemeSymbian::platformActiveSelectionForegroundColor() const |
|
214 { |
|
215 TRgb c = CEikonEnv::Static()->Color(EColorControlHighlightText); |
|
216 return Color(c.Red(),c.Green(),c.Blue()); |
|
217 } |
|
218 |
|
219 Color RenderThemeSymbian::platformInactiveSelectionForegroundColor() const |
|
220 { |
|
221 return platformActiveSelectionForegroundColor(); |
|
222 } |
|
223 |
|
224 bool RenderThemeSymbian::paintCheckbox(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
225 { |
|
226 paintButtonDecorations(o, i, r); |
|
227 MScrollView* wv = scrollView(i); |
|
228 // don't scale the checkbox if scalingFactor is 100% or we are in the process of scaling another image |
|
229 if (wv->scalingFactor() <= 100 || m_bitmapScaler) { |
|
230 i.context->drawImage(isChecked(o)?m_checkBoxOn:m_checkBoxOff,r); |
|
231 } |
|
232 // use the cached scaled image if it has the same scaling factor |
|
233 else if (wv->scalingFactor() == (isChecked(o) ? m_scalingForCheckBoxOn : m_scalingForCheckBoxOff)) { |
|
234 i.context->drawImage(isChecked(o) ? m_scaledCheckBoxOn : m_scaledCheckBoxOff, r); |
|
235 } |
|
236 // scale |
|
237 else { |
|
238 scaleImage(isChecked(o) ? ECheckBoxOn : ECheckBoxOff, wv->scalingFactor()); |
|
239 if (wv->scalingFactor() == (isChecked(o) ? m_scalingForCheckBoxOn : m_scalingForCheckBoxOff)) { |
|
240 i.context->drawImage(isChecked(o) ? m_scaledCheckBoxOn : m_scaledCheckBoxOff, r); |
|
241 } |
|
242 else { |
|
243 i.context->drawImage(isChecked(o)?m_checkBoxOn:m_checkBoxOff,r); |
|
244 } |
|
245 } |
|
246 return false; |
|
247 } |
|
248 |
|
249 bool RenderThemeSymbian::paintRadio(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
250 { |
|
251 if (!m_radioButtonOn) { |
|
252 m_radioButtonOn = Image::loadPlatformResource("radioButtonOn"); |
|
253 m_radioButtonOff = Image::loadPlatformResource("radioButtonOff"); |
|
254 } |
|
255 paintButtonDecorations(o, i, r); |
|
256 MScrollView* wv = scrollView(i); |
|
257 // don't scale the checkbox if scalingFactor is 100% or we are in the process of scaling another image |
|
258 if (wv->scalingFactor() <= 100 || m_bitmapScaler) { |
|
259 i.context->drawImage(isChecked(o)?m_radioButtonOn:m_radioButtonOff,r); |
|
260 } |
|
261 // use the cached scaled image if it has the same scaling factor |
|
262 else if (wv->scalingFactor() == (isChecked(o) ? m_scalingForRadioOn : m_scalingForRadioOff)) { |
|
263 i.context->drawImage(isChecked(o) ? m_scaledRadioOn : m_scaledRadioOff, r); |
|
264 } |
|
265 // scale |
|
266 else { |
|
267 scaleImage(isChecked(o) ? ERadioOn : ERadioOff, wv->scalingFactor()); |
|
268 if (wv->scalingFactor() == (isChecked(o) ? m_scalingForRadioOn : m_scalingForRadioOff)) { |
|
269 i.context->drawImage(isChecked(o) ? m_scaledRadioOn : m_scaledRadioOff, r); |
|
270 } |
|
271 else { |
|
272 i.context->drawImage(isChecked(o)?m_radioButtonOn:m_radioButtonOff,r); |
|
273 } |
|
274 } |
|
275 return false; |
|
276 } |
|
277 |
|
278 bool RenderThemeSymbian::isControlStyled(const RenderStyle* style, const BorderData& border, |
|
279 const BackgroundLayer& background, const Color& backgroundColor) const |
|
280 { |
|
281 if (style->appearance() == TextFieldAppearance || style->appearance() == TextAreaAppearance) |
|
282 return style->border() != border; |
|
283 |
|
284 return RenderTheme::isControlStyled(style, border, background, backgroundColor); |
|
285 } |
|
286 |
|
287 bool RenderThemeSymbian::controlSupportsTints(const RenderObject* o) const |
|
288 { |
|
289 return false; |
|
290 } |
|
291 |
|
292 void RenderThemeSymbian::addIntrinsicMargins(RenderStyle* style) const |
|
293 { |
|
294 // Cut out the intrinsic margins completely if we end up using a small font size |
|
295 if (style->fontSize() < 11) |
|
296 return; |
|
297 |
|
298 // Intrinsic margin value. |
|
299 const int m = 2; |
|
300 |
|
301 // FIXME: Using width/height alone and not also dealing with min-width/max-width is flawed. |
|
302 if (style->width().isIntrinsicOrAuto()) { |
|
303 if (style->marginLeft().quirk()) |
|
304 style->setMarginLeft(Length(m, Fixed)); |
|
305 |
|
306 if (style->marginRight().quirk()) |
|
307 style->setMarginRight(Length(m, Fixed)); |
|
308 } |
|
309 |
|
310 if (style->height().isAuto()) { |
|
311 if (style->marginTop().quirk()) |
|
312 style->setMarginTop(Length(m, Fixed)); |
|
313 |
|
314 if (style->marginBottom().quirk()) |
|
315 style->setMarginBottom(Length(m, Fixed)); |
|
316 } |
|
317 } |
|
318 |
|
319 void RenderThemeSymbian::setCheckboxSize(RenderStyle* style) const |
|
320 { |
|
321 // If the width and height are both specified, then we have nothing to do. |
|
322 if (!style->width().isIntrinsicOrAuto() && !style->height().isAuto()) |
|
323 return; |
|
324 |
|
325 if (style->width().isIntrinsicOrAuto()) |
|
326 style->setWidth(Length(m_checkBoxOn->width(), Fixed)); |
|
327 |
|
328 if (style->height().isAuto()) |
|
329 style->setHeight(Length(m_checkBoxOn->height(), Fixed)); |
|
330 } |
|
331 |
|
332 void RenderThemeSymbian::setRadioSize(RenderStyle* style) const |
|
333 { |
|
334 // This is the same as checkboxes. |
|
335 setCheckboxSize(style); |
|
336 } |
|
337 |
|
338 bool RenderThemeSymbian::supportsFocus(EAppearance appearance) const |
|
339 { |
|
340 return false; |
|
341 } |
|
342 |
|
343 |
|
344 void RenderThemeSymbian::adjustButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
|
345 { |
|
346 addIntrinsicMargins(style); |
|
347 } |
|
348 |
|
349 bool RenderThemeSymbian::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
350 { |
|
351 i.context->save(); |
|
352 IntRect clipRect(intersection(r, i.rect)); |
|
353 i.context->clip(clipRect); |
|
354 EAppearance appearance = o->style()->appearance(); |
|
355 IntRect innerRect(r); |
|
356 IntSize cr(1,1); |
|
357 for (int j = 4; j > 0; --j) { |
|
358 innerRect.setSize(innerRect.size() - IntSize(1,1)); |
|
359 i.context->fillRoundedRect(innerRect, IntSize(1,1), IntSize(1,1), IntSize(1,1), IntSize(1,1), Color(226 - j*10, 226 - j*10, 226 - j*2)); |
|
360 } |
|
361 |
|
362 i.context->restore(); |
|
363 return false; |
|
364 } |
|
365 |
|
366 void RenderThemeSymbian::adjustTextFieldStyle(CSSStyleSelector*, RenderStyle* style, Element*) const |
|
367 { |
|
368 addIntrinsicMargins(style); |
|
369 } |
|
370 |
|
371 bool RenderThemeSymbian::paintTextField(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
372 { |
|
373 i.context->setStrokeColor(Color::black); |
|
374 i.context->setStrokeThickness(1.0f); |
|
375 i.context->setFillColor(Color::transparent); |
|
376 i.context->drawRect(r); |
|
377 return false; |
|
378 } |
|
379 |
|
380 bool RenderThemeSymbian::paintTextArea(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
381 { |
|
382 i.context->setStrokeColor(Color::black); |
|
383 i.context->setStrokeThickness(1.0f); |
|
384 i.context->setFillColor(Color::transparent); |
|
385 i.context->drawRect(r); |
|
386 return false; |
|
387 } |
|
388 |
|
389 bool RenderThemeSymbian::paintMenuListButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
390 { |
|
391 if (!m_selectArrow) { |
|
392 m_selectArrow = Image::loadPlatformResource("selectArrow"); |
|
393 } |
|
394 IntSize s = m_selectArrow->size(); |
|
395 |
|
396 // draw the bounding area |
|
397 i.context->save(); |
|
398 //i.context->setPen(Pen(Color::black,1)); |
|
399 i.context->setFillColor(Color::lightGray); |
|
400 |
|
401 IntRect brect(r.x() + r.width() - s.width(), r.y(), s.width(), r.height() - 3 ); |
|
402 i.context->drawRect(r); |
|
403 paintButtonDecorations(o, i, r); |
|
404 |
|
405 // draw the arrow |
|
406 int y = (r.height() - s.height())/2 + r.y(); |
|
407 IntRect arrowRect(IntPoint(r.x() + r.width() - s.width(), y), s); |
|
408 MScrollView* wv = scrollView(i); |
|
409 // don't scale the checkbox if scalingFactor is 100% or we are in the process of scaling another image |
|
410 if (wv->scalingFactor() <= 100 || m_bitmapScaler) { |
|
411 i.context->drawImage(m_selectArrow, arrowRect); |
|
412 } |
|
413 // use the cached scaled image if it has the same scaling factor |
|
414 else if (wv->scalingFactor() == (m_scalingForSelectArrow)) { |
|
415 i.context->drawImage(m_scaledSelectArrow, arrowRect); |
|
416 } |
|
417 // scale |
|
418 else { |
|
419 scaleImage(ESelectArrow, wv->scalingFactor()); |
|
420 if (wv->scalingFactor() == m_scalingForSelectArrow) { |
|
421 i.context->drawImage(m_scaledSelectArrow, arrowRect); |
|
422 } |
|
423 else { |
|
424 i.context->drawImage(m_selectArrow, arrowRect); |
|
425 } |
|
426 } |
|
427 i.context->restore(); |
|
428 return false; |
|
429 } |
|
430 |
|
431 bool RenderThemeSymbian::paintMenuList(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
432 { |
|
433 EAppearance appearance = o->style()->appearance(); |
|
434 i.context->save(); |
|
435 i.context->setStrokeColor(Color::black); |
|
436 i.context->setStrokeThickness(1.0f); |
|
437 i.context->setFillColor(Color::lightGray); |
|
438 i.context->drawRect(r); |
|
439 |
|
440 if (!m_selectArrow) { |
|
441 m_selectArrow = Image::loadPlatformResource("selectArrow"); |
|
442 } |
|
443 |
|
444 MScrollView* wv = scrollView(i); |
|
445 IntSize s = m_selectArrow->size(); |
|
446 int y = (r.height() - s.height())/2 + r.y(); |
|
447 IntRect imrect(IntPoint(r.x()+r.width()-s.width(), y), s); |
|
448 // don't scale the checkbox if scalingFactor is 100% or we are in the process of scaling another image |
|
449 if (wv->scalingFactor() <= 100 || m_bitmapScaler) { |
|
450 i.context->drawImage(m_selectArrow, imrect); |
|
451 } |
|
452 // use the cached scaled image if it has the same scaling factor |
|
453 else if (wv->scalingFactor() == (m_scalingForSelectArrow)) { |
|
454 i.context->drawImage(m_scaledSelectArrow, imrect); |
|
455 } |
|
456 // scale |
|
457 else { |
|
458 scaleImage(ESelectArrow, wv->scalingFactor()); |
|
459 if (wv->scalingFactor() == m_scalingForSelectArrow) { |
|
460 i.context->drawImage(m_scaledSelectArrow, imrect); |
|
461 } |
|
462 else { |
|
463 i.context->drawImage(m_selectArrow, imrect); |
|
464 } |
|
465 } |
|
466 i.context->restore(); |
|
467 return false; |
|
468 } |
|
469 |
|
470 void RenderThemeSymbian::adjustMenuListStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
|
471 { |
|
472 style->setPaddingLeft(Length(3, Fixed)); |
|
473 style->setPaddingRight(Length(20, Fixed)); |
|
474 style->setPaddingTop(Length(3, Fixed)); |
|
475 style->setPaddingBottom(Length(3, Fixed)); |
|
476 } |
|
477 |
|
478 void RenderThemeSymbian::adjustMenuListButtonStyle(CSSStyleSelector* selector, RenderStyle* style, Element* e) const |
|
479 { |
|
480 style->setPaddingLeft(Length(3, Fixed)); |
|
481 style->setPaddingRight(Length(20, Fixed)); |
|
482 style->setPaddingTop(Length(3, Fixed)); |
|
483 style->setPaddingBottom(Length(3, Fixed)); |
|
484 } |
|
485 |
|
486 void RenderThemeSymbian::paintButtonDecorations(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r) |
|
487 { |
|
488 RenderBox* b = static_cast<RenderBox*>(o); |
|
489 int my = max(r.y(), i.rect.y()); |
|
490 int mh; |
|
491 if (r.y() < i.rect.y()) |
|
492 mh = max(0, r.height() - (i.rect.y() - r.y())); |
|
493 else |
|
494 mh = std::min(i.rect.height(), r.height()); |
|
495 |
|
496 if (o->style()->hasBackground()) { |
|
497 b->paintBackgroundExtended(i.context, o->style()->backgroundColor(), o->style()->backgroundLayers(), my, mh, r.x(), r.y(), r.width(), r.height()); |
|
498 } |
|
499 if (o->style()->hasBorder()) { |
|
500 b->paintBorder(i.context, r.x(), r.y(), r.width(), r.height(), o->style()); |
|
501 } |
|
502 } |
|
503 |
|
504 bool RenderThemeSymbian::supportsFocusRing(const RenderStyle* style) const |
|
505 { |
|
506 // force webcore to draw focus ring. |
|
507 return false; |
|
508 } |
|
509 |
|
510 void RenderThemeSymbian::scaleImage(int type, int scalingFactor) |
|
511 { |
|
512 TRAP_IGNORE(scaleImageL(type, scalingFactor)); |
|
513 if (m_bitmapScaler) { |
|
514 // should happen only as result of a leave |
|
515 delete m_bitmapScaler; |
|
516 m_bitmapScaler = NULL; |
|
517 } |
|
518 } |
|
519 |
|
520 void RenderThemeSymbian::scaleImageL(int type, int scalingFactor) |
|
521 { |
|
522 Image* image = NULL; |
|
523 switch (type) { |
|
524 case ECheckBoxOn: |
|
525 image = m_checkBoxOn; |
|
526 break; |
|
527 case ECheckBoxOff: |
|
528 image = m_checkBoxOff; |
|
529 break; |
|
530 case ERadioOn: |
|
531 image = m_radioButtonOn; |
|
532 break; |
|
533 case ERadioOff: |
|
534 image = m_radioButtonOff; |
|
535 break; |
|
536 case ESelectArrow: |
|
537 image = m_selectArrow; |
|
538 break; |
|
539 } |
|
540 CMaskedBitmap* maskedBitmap = image->getMaskedBitmap(); |
|
541 if (!maskedBitmap) User::Leave(KErrGeneral); // should not really happen |
|
542 TSize size = maskedBitmap->SizeInPixels(); |
|
543 size.iWidth = (size.iWidth * scalingFactor) / 100; |
|
544 size.iHeight = (size.iHeight * scalingFactor) / 100; |
|
545 SyncScaler syncScaler; |
|
546 TRequestStatus* status = &(syncScaler.iStatus); |
|
547 |
|
548 m_bitmapScaler = CBitmapScaler::NewL(); |
|
549 m_bitmapScaler->SetQualityAlgorithm(CBitmapScaler::EMaximumQuality); |
|
550 // bitmap; |
|
551 CFbsBitmap* bitmap = const_cast<CFbsBitmap*>(&(maskedBitmap->Bitmap())); |
|
552 CFbsBitmap* resultBitmap = NULL; |
|
553 resultBitmap = new (ELeave) CFbsBitmap; |
|
554 CleanupStack::PushL(resultBitmap); |
|
555 resultBitmap->Create(size, EColor16M); |
|
556 syncScaler.init(); |
|
557 m_bitmapScaler->Scale(status, *bitmap, *resultBitmap, ETrue); |
|
558 if (!m_asw) m_asw = new (ELeave) CActiveSchedulerWait(); |
|
559 m_asw->Start(); |
|
560 // If an error occured during scaling, stop! |
|
561 User::LeaveIfError(syncScaler.m_error); |
|
562 |
|
563 // mask |
|
564 CFbsBitmap* mask = const_cast<CFbsBitmap*>(&(maskedBitmap->Mask())); |
|
565 CFbsBitmap* resultMask = NULL; |
|
566 resultMask = new (ELeave) CFbsBitmap; |
|
567 CleanupStack::PushL(resultMask); |
|
568 resultMask->Create(size, EGray256); |
|
569 syncScaler.init(); |
|
570 m_bitmapScaler->Scale(status, (*mask), *resultMask, ETrue); |
|
571 if (!m_asw) m_asw = new (ELeave) CActiveSchedulerWait(); |
|
572 m_asw->Start(); |
|
573 // If an error occured during scaling, stop! |
|
574 User::LeaveIfError(syncScaler.m_error); |
|
575 |
|
576 CMaskedBitmap* mb = NULL; |
|
577 mb = new(ELeave) CMaskedBitmap(resultBitmap, resultMask); |
|
578 CleanupStack::Pop(2); // resultBitmap, resultMask |
|
579 CleanupStack::PushL(mb); |
|
580 BitmapImage* bi = new (ELeave) BitmapImage(mb); |
|
581 CleanupStack::Pop(); // mb |
|
582 switch (type) { |
|
583 case ECheckBoxOn: |
|
584 delete m_scaledCheckBoxOn; |
|
585 m_scaledCheckBoxOn = bi; |
|
586 m_scalingForCheckBoxOn = scalingFactor; |
|
587 break; |
|
588 case ECheckBoxOff: |
|
589 delete m_scaledCheckBoxOff; |
|
590 m_scaledCheckBoxOff = bi; |
|
591 m_scalingForCheckBoxOff = scalingFactor; |
|
592 break; |
|
593 case ERadioOn: |
|
594 delete m_scaledRadioOn; |
|
595 m_scaledRadioOn = bi; |
|
596 m_scalingForRadioOn = scalingFactor; |
|
597 break; |
|
598 case ERadioOff: |
|
599 delete m_scaledRadioOff; |
|
600 m_scaledRadioOff = bi; |
|
601 m_scalingForRadioOff = scalingFactor; |
|
602 break; |
|
603 case ESelectArrow: |
|
604 delete m_scaledSelectArrow; |
|
605 m_scaledSelectArrow = bi; |
|
606 m_scalingForSelectArrow = scalingFactor; |
|
607 break; |
|
608 } |
|
609 delete m_bitmapScaler; |
|
610 m_bitmapScaler = NULL; |
|
611 delete m_asw; |
|
612 m_asw = NULL; |
|
613 } |
|
614 |
|
615 void RenderThemeSymbian::run() |
|
616 { |
|
617 m_asw->AsyncStop(); |
|
618 } |
|
619 |
|
620 void RenderThemeSymbian::cancel() |
|
621 { |
|
622 // Since the operation is very fast, not sure what could cause it to be canceled. |
|
623 if (m_bitmapScaler) { |
|
624 m_bitmapScaler->Cancel(); |
|
625 } |
|
626 if (m_asw && m_asw->IsStarted()) { |
|
627 m_asw->AsyncStop(); |
|
628 } |
|
629 } |
|
630 |
|
631 } |