Changeset 127786 in webkit
- Timestamp:
- Sep 6, 2012 2:41:34 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r127783 r127786 1 2012-09-06 Kenneth Rohde Christiansen <kenneth@webkit.org> 2 3 [EFL] Fuzzy load the Edje theme for HTML forms 4 https://bugs.webkit.org/show_bug.cgi?id=95832 5 6 Reviewed by Antonio Gomes. 7 8 Change the theme so that it is first loaded when actually used. 9 This also fixed the case that it was impossible to change theme 10 a second time. 11 12 Tested by current tests. API unit test coming in separate patch. 13 14 * platform/efl/RenderThemeEfl.cpp: 15 (WebCore): 16 17 Add some convenience macros. 18 19 (WebCore::applyColorCallback): 20 21 Use just one callback from the edje theme, which just calls 22 setColorFromThemeClass. 23 24 (WebCore::fillColorsFromEdjeClass): 25 26 Add convenience method for receiving colors from Edje and 27 storing them in Color's. 28 29 (WebCore::RenderThemeEfl::setColorFromThemeClass): 30 31 Set the class Color variabled with the values from the theme 32 color class. 33 34 (WebCore::RenderThemeEfl::setThemePath): 35 36 Don't apply the theme immediately. 37 38 (WebCore::RenderThemeEfl::loadTheme): 39 40 Load the new theme and free the current one. If it fails, 41 it will continue using the old one, if exists. 42 43 (WebCore::RenderThemeEfl::adjustSizeConstraints): 44 (WebCore::RenderThemeEfl::themePartCacheEntryReset): 45 (WebCore::RenderThemeEfl::cacheThemePartNew): 46 (WebCore::RenderThemeEfl::paintThemePart): 47 (WebCore::RenderThemeEfl::applyPartDescriptionsFrom): 48 (WebCore::RenderThemeEfl::platformActiveSelectionBackgroundColor): 49 (WebCore::RenderThemeEfl::platformInactiveSelectionBackgroundColor): 50 (WebCore::RenderThemeEfl::platformActiveSelectionForegroundColor): 51 (WebCore::RenderThemeEfl::platformInactiveSelectionForegroundColor): 52 (WebCore::RenderThemeEfl::platformFocusRingColor): 53 54 Ensure the theme is loaded. 55 56 (WebCore::RenderThemeEfl::adjustCheckboxStyle): 57 (WebCore::RenderThemeEfl::adjustRadioStyle): 58 (WebCore::RenderThemeEfl::emitMediaButtonSignal): 59 60 Ensure the theme is loaded. 61 62 * platform/efl/RenderThemeEfl.h: 63 (RenderThemeEfl): 64 (WebCore::RenderThemeEfl::loadThemeIfNeeded): 65 66 Remove unneeded methods and add a method for loading a theme 67 in the case it is not loaded yet. 68 1 69 2012-09-06 Simon Fraser <simon.fraser@apple.com> 2 70 -
trunk/Source/WebCore/platform/efl/RenderThemeEfl.cpp
r127626 r127786 80 80 #endif 81 81 82 #define _ASSERT_ON_RELEASE_RETURN(o, fmt, ...) \ 83 do { if (!o) { EINA_LOG_CRIT(fmt, ## __VA_ARGS__); ASSERT(o); return; } } while (0) 84 #define _ASSERT_ON_RELEASE_RETURN_VAL(o, val, fmt, ...) \ 85 do { if (!o) { EINA_LOG_CRIT(fmt, ## __VA_ARGS__); ASSERT(o); return val; } } while (0) 86 82 87 void RenderThemeEfl::adjustSizeConstraints(RenderStyle* style, FormType type) const 83 88 { 89 loadThemeIfNeeded(); 90 _ASSERT_ON_RELEASE_RETURN(m_edje, "Could not paint native HTML part due to missing theme."); 91 84 92 const struct ThemePartDesc* desc = m_partDescs + (size_t)type; 85 93 … … 115 123 Edje_Load_Error err = edje_object_load_error_get(entry->o); 116 124 const char *errmsg = edje_load_error_str(err); 117 EINA_LOG_ERR("Could not load '%s' from theme %s: %s", 118 group, file, errmsg); 125 EINA_LOG_ERR("Could not load '%s' from theme %s: %s", group, file, errmsg); 119 126 return false; 120 127 } … … 160 167 { 161 168 if (isFormElementTooLargeToDisplay(size)) { 162 EINA_LOG_ERR(" cannot render an element of size %dx%d", size.width(), size.height());169 EINA_LOG_ERR("Cannot render an element of size %dx%d.", size.width(), size.height()); 163 170 return 0; 164 171 } … … 312 319 bool RenderThemeEfl::paintThemePart(RenderObject* object, FormType type, const PaintInfo& info, const IntRect& rect) 313 320 { 321 loadThemeIfNeeded(); 322 _ASSERT_ON_RELEASE_RETURN_VAL(m_edje, false, "Could not paint native HTML part due to missing theme."); 323 314 324 ThemePartCacheEntry* entry; 315 325 Eina_List* updates; 316 326 cairo_t* cairo; 317 318 ASSERT(m_canvas);319 ASSERT(m_edje);320 327 321 328 entry = cacheThemePartGet(type, rect.size()); … … 400 407 } 401 408 402 static void renderThemeEflColorClassSelectionActive(void* data, Evas_Object* object, const char* signal, const char* source) 403 { 404 RenderThemeEfl* that = static_cast<RenderThemeEfl *>(data); 405 int fr, fg, fb, fa, br, bg, bb, ba; 406 407 if (!edje_object_color_class_get(object, source, &fr, &fg, &fb, &fa, &br, &bg, &bb, &ba, 0, 0, 0, 0)) 408 return; 409 410 that->setActiveSelectionColor(fr, fg, fb, fa, br, bg, bb, ba); 411 } 412 413 static void renderThemeEflColorClassSelectionInactive(void* data, Evas_Object* object, const char* signal, const char* source) 414 { 415 RenderThemeEfl* that = static_cast<RenderThemeEfl *>(data); 416 int fr, fg, fb, fa, br, bg, bb, ba; 417 418 if (!edje_object_color_class_get(object, source, &fr, &fg, &fb, &fa, &br, &bg, &bb, &ba, 0, 0, 0, 0)) 419 return; 420 421 that->setInactiveSelectionColor(fr, fg, fb, fa, br, bg, bb, ba); 422 } 423 424 static void renderThemeEflColorClassFocusRing(void* data, Evas_Object* object, const char* signal, const char* source) 425 { 426 RenderThemeEfl* that = static_cast<RenderThemeEfl *>(data); 427 int fr, fg, fb, fa; 428 429 if (!edje_object_color_class_get(object, source, &fr, &fg, &fb, &fa, 0, 0, 0, 0, 0, 0, 0, 0)) 430 return; 431 432 that->setFocusRingColor(fr, fg, fb, fa); 409 static void applyColorCallback(void* data, Evas_Object*, const char* /* signal */, const char* colorClass) 410 { 411 RenderThemeEfl* that = static_cast<RenderThemeEfl*>(data); 412 that->setColorFromThemeClass(colorClass); 413 that->platformColorsDidChange(); // Triggers relayout. 414 } 415 416 static void fillColorsFromEdjeClass(Evas_Object* o, const char* colorClass, Color* color1, Color* color2 = 0, Color* color3 = 0) 417 { 418 int r1, g1, b1, a1; 419 int r2, g2, b2, a2; 420 int r3, g3, b3, a3; 421 422 bool ok = edje_object_color_class_get(o, colorClass, &r1, &g1, &b1, &a1, &r2, &g2, &b2, &a2, &r3, &g3, &b3, &a3); 423 _ASSERT_ON_RELEASE_RETURN(ok, "Could not get color class '%s'\n", colorClass); 424 425 if (color1) 426 color1->setRGB(makeRGBA(r1, g1, b1, a1)); 427 if (color2) 428 color2->setRGB(makeRGBA(r2, g2, b2, a2)); 429 if (color3) 430 color3->setRGB(makeRGBA(r3, g3, b3, a3)); 431 } 432 433 void RenderThemeEfl::setColorFromThemeClass(const char* colorClass) 434 { 435 ASSERT(m_edje); 436 437 if (!strcmp("webkit/selection/active", colorClass)) 438 fillColorsFromEdjeClass(m_edje, colorClass, &m_activeSelectionForegroundColor, &m_activeSelectionBackgroundColor); 439 else if (!strcmp("webkit/selection/inactive", colorClass)) 440 fillColorsFromEdjeClass(m_edje, colorClass, &m_inactiveSelectionForegroundColor, &m_inactiveSelectionBackgroundColor); 441 else if (!strcmp("webkit/focus_ring", colorClass)) { 442 fillColorsFromEdjeClass(m_edje, colorClass, &m_focusRingColor); 443 // platformFocusRingColor() is only used for the default theme (without page) 444 // The following is ugly, but no other way to do it unless we change it to use page themes as much as possible. 445 RenderTheme::setCustomFocusRingColor(m_focusRingColor); 446 } 433 447 } 434 448 … … 439 453 440 454 m_themePath = path; 441 themeChanged(); 442 } 443 444 void RenderThemeEfl::createCanvas() 445 { 446 ASSERT(!m_canvas); 447 m_canvas = ecore_evas_buffer_new(1, 1); 448 ASSERT(m_canvas); 449 } 450 451 void RenderThemeEfl::createEdje() 452 { 453 ASSERT(!m_edje); 454 if (m_themePath.isEmpty()) 455 EINA_LOG_ERR("No theme defined, unable to set RenderThemeEfl."); 456 else { 457 m_edje = edje_object_add(ecore_evas_get(m_canvas)); 458 if (!m_edje) 459 EINA_LOG_ERR("Could not create base edje object."); 460 else if (!edje_object_file_set(m_edje, m_themePath.utf8().data(), "webkit/base")) { 461 Edje_Load_Error err = edje_object_load_error_get(m_edje); 462 const char* errmsg = edje_load_error_str(err); 463 EINA_LOG_ERR("Could not set file: %s", errmsg); 464 evas_object_del(m_edje); 465 m_edje = 0; 466 } else { 467 #define CONNECT(cc, func) \ 468 edje_object_signal_callback_add(m_edje, "color_class,set", \ 469 "webkit/"cc, func, this) 470 471 CONNECT("selection/active", 472 renderThemeEflColorClassSelectionActive); 473 CONNECT("selection/inactive", 474 renderThemeEflColorClassSelectionInactive); 475 CONNECT("focus_ring", renderThemeEflColorClassFocusRing); 476 #undef CONNECT 477 } 478 } 479 } 480 481 void RenderThemeEfl::applyEdjeColors() 482 { 483 int fr, fg, fb, fa, br, bg, bb, ba; 484 ASSERT(m_edje); 485 #define COLOR_GET(cls) \ 486 edje_object_color_class_get(m_edje, "webkit/"cls, \ 487 &fr, &fg, &fb, &fa, &br, &bg, &bb, &ba, \ 488 0, 0, 0, 0) 489 490 if (COLOR_GET("selection/active")) { 491 m_activeSelectionForegroundColor = Color(fr, fg, fb, fa); 492 m_activeSelectionBackgroundColor = Color(br, bg, bb, ba); 493 } 494 if (COLOR_GET("selection/inactive")) { 495 m_inactiveSelectionForegroundColor = Color(fr, fg, fb, fa); 496 m_inactiveSelectionBackgroundColor = Color(br, bg, bb, ba); 497 } 498 if (COLOR_GET("focus_ring")) { 499 m_focusRingColor = Color(fr, fg, fb, fa); 500 // webkit just use platformFocusRingColor() for default theme (without page) 501 // this is ugly, but no other way to do it unless we change 502 // it to use page themes as much as possible. 503 RenderTheme::setCustomFocusRingColor(m_focusRingColor); 504 } 505 #undef COLOR_GET 506 platformColorsDidChange(); 455 456 if (m_themePath.isEmpty()) { 457 EINA_LOG_ERR("No theme defined, unable to set theme for HTML Forms."); 458 return; 459 } 460 461 if (!m_canvas) { 462 m_canvas = ecore_evas_buffer_new(1, 1); 463 if (!m_canvas) 464 EINA_LOG_ERR("Could not create canvas."); 465 } 466 467 loadTheme(); 468 } 469 470 bool RenderThemeEfl::loadTheme() 471 { 472 Evas_Object* o = edje_object_add(ecore_evas_get(m_canvas)); 473 _ASSERT_ON_RELEASE_RETURN_VAL(o, false, "Could not create new base Edje object."); 474 475 if (!edje_object_file_set(o, m_themePath.utf8().data(), "webkit/base")) { 476 Edje_Load_Error err = edje_object_load_error_get(o); 477 const char* errmsg = edje_load_error_str(err); 478 EINA_LOG_ERR("Could not set file '%s': %s", m_themePath.utf8().data(), errmsg); 479 evas_object_del(o); 480 return false; // Keep current theme. 481 } 482 483 // Get rid of existing theme. 484 if (m_edje) { 485 cacheThemePartFlush(); 486 evas_object_del(m_edje); 487 } 488 489 // Set new loaded theme, and apply it. 490 m_edje = o; 491 492 edje_object_signal_callback_add(m_edje, "color_class,set", "webkit/selection/active", applyColorCallback, this); 493 edje_object_signal_callback_add(m_edje, "color_class,set", "webkit/selection/inactive", applyColorCallback, this); 494 edje_object_signal_callback_add(m_edje, "color_class,set", "webkit/focus_ring", applyColorCallback, this); 495 496 applyPartDescriptionsFrom(m_edje); 497 498 setColorFromThemeClass("webkit/selection/active"); 499 setColorFromThemeClass("webkit/selection/inactive"); 500 setColorFromThemeClass("webkit/focus_ring"); 501 502 platformColorsDidChange(); // Schedules a relayout, do last. 503 504 return true; 507 505 } 508 506 … … 606 604 } 607 605 608 void RenderThemeEfl::applyPartDescriptions ()606 void RenderThemeEfl::applyPartDescriptionsFrom(Evas_Object* o) 609 607 { 610 608 Evas_Object* object; … … 612 610 const char* file; 613 611 614 ASSERT(m_canvas); 615 ASSERT(m_edje); 616 617 edje_object_file_get(m_edje, &file, 0); 612 ASSERT(o); 613 614 edje_object_file_get(o, &file, 0); 618 615 ASSERT(file); 616 if (!file) { 617 EINA_LOG_ERR("Could not retrieve Edje theme file."); 618 return; 619 } 619 620 620 621 object = edje_object_add(ecore_evas_get(m_canvas)); … … 639 640 } 640 641 evas_object_del(object); 641 }642 643 void RenderThemeEfl::themeChanged()644 {645 cacheThemePartFlush();646 647 if (!m_canvas) {648 createCanvas();649 if (!m_canvas)650 return;651 }652 653 if (!m_edje) {654 createEdje();655 if (!m_edje)656 return;657 }658 659 applyEdjeColors();660 applyPartDescriptions();661 642 } 662 643 … … 688 669 ecore_evas_free(m_canvas); 689 670 } 690 }691 692 void RenderThemeEfl::setActiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA)693 {694 m_activeSelectionForegroundColor = Color(foreR, foreG, foreB, foreA);695 m_activeSelectionBackgroundColor = Color(backR, backG, backB, backA);696 platformColorsDidChange();697 }698 699 void RenderThemeEfl::setInactiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA)700 {701 m_inactiveSelectionForegroundColor = Color(foreR, foreG, foreB, foreA);702 m_inactiveSelectionBackgroundColor = Color(backR, backG, backB, backA);703 platformColorsDidChange();704 }705 706 void RenderThemeEfl::setFocusRingColor(int r, int g, int b, int a)707 {708 m_focusRingColor = Color(r, g, b, a);709 // webkit just use platformFocusRingColor() for default theme (without page)710 // this is ugly, but no other way to do it unless we change711 // it to use page themes as much as possible.712 RenderTheme::setCustomFocusRingColor(m_focusRingColor);713 platformColorsDidChange();714 671 } 715 672 … … 755 712 } 756 713 714 Color RenderThemeEfl::platformActiveSelectionBackgroundColor() const 715 { 716 loadThemeIfNeeded(); 717 return m_activeSelectionBackgroundColor; 718 } 719 720 Color RenderThemeEfl::platformInactiveSelectionBackgroundColor() const 721 { 722 loadThemeIfNeeded(); 723 return m_inactiveSelectionBackgroundColor; 724 } 725 726 Color RenderThemeEfl::platformActiveSelectionForegroundColor() const 727 { 728 loadThemeIfNeeded(); 729 return m_activeSelectionForegroundColor; 730 } 731 732 Color RenderThemeEfl::platformInactiveSelectionForegroundColor() const 733 { 734 loadThemeIfNeeded(); 735 return m_inactiveSelectionForegroundColor; 736 } 737 738 Color RenderThemeEfl::platformFocusRingColor() const 739 { 740 loadThemeIfNeeded(); 741 return m_focusRingColor; 742 } 743 757 744 bool RenderThemeEfl::paintSliderTrack(RenderObject* object, const PaintInfo& info, const IntRect& rect) 758 745 { … … 843 830 return; 844 831 } 832 845 833 adjustSizeConstraints(style, CheckBox); 834 ASSERT(m_edje); 835 846 836 style->resetBorder(); 847 837 … … 864 854 return; 865 855 } 856 866 857 adjustSizeConstraints(style, RadioButton); 858 ASSERT(m_edje); 859 867 860 style->resetBorder(); 868 861 … … 1087 1080 bool RenderThemeEfl::emitMediaButtonSignal(FormType formType, MediaControlElementType mediaElementType, const IntRect& rect) 1088 1081 { 1082 loadThemeIfNeeded(); 1083 _ASSERT_ON_RELEASE_RETURN_VAL(m_edje, false, "Could not paint native HTML part due to missing theme."); 1084 1089 1085 ThemePartCacheEntry* entry; 1090 1086 1091 1087 entry = cacheThemePartGet(formType, rect.size()); 1092 ASSERT(entry); 1093 if (!entry) 1094 return false; 1088 _ASSERT_ON_RELEASE_RETURN_VAL(entry, false, "Could not paint native HTML part due to missing theme part."); 1095 1089 1096 1090 if (mediaElementType == MediaPlayButton) … … 1281 1275 } 1282 1276 #endif 1283 } 1277 1278 #undef _ASSERT_ON_RELEASE_RETURN 1279 #undef _ASSERT_ON_RELEASE_RETURN_VAL 1280 1281 } -
trunk/Source/WebCore/platform/efl/RenderThemeEfl.h
r127723 r127786 97 97 virtual LayoutUnit baselinePosition(const RenderObject*) const; 98 98 99 virtual Color platformActiveSelectionBackgroundColor() const { return m_activeSelectionBackgroundColor; } 100 virtual Color platformInactiveSelectionBackgroundColor() const { return m_inactiveSelectionBackgroundColor; } 101 virtual Color platformActiveSelectionForegroundColor() const { return m_activeSelectionForegroundColor; } 102 virtual Color platformInactiveSelectionForegroundColor() const { return m_inactiveSelectionForegroundColor; } 103 virtual Color platformFocusRingColor() const { return m_focusRingColor; } 104 105 virtual void themeChanged(); 106 107 // Set platform colors and notify they changed 108 void setActiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA); 109 void setInactiveSelectionColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA); 110 void setFocusRingColor(int r, int g, int b, int a); 99 virtual Color platformActiveSelectionBackgroundColor() const; 100 virtual Color platformInactiveSelectionBackgroundColor() const; 101 virtual Color platformActiveSelectionForegroundColor() const; 102 virtual Color platformInactiveSelectionForegroundColor() const; 103 virtual Color platformFocusRingColor() const; 104 105 // Set platform colors; remember to call platformColorDidChange after. 106 void setColorFromThemeClass(const char* colorClass); 111 107 112 108 void setButtonTextColor(int foreR, int foreG, int foreB, int foreA, int backR, int backG, int backB, int backA); … … 116 112 117 113 void adjustSizeConstraints(RenderStyle*, FormType) const; 118 119 114 120 115 // System fonts. … … 210 205 void setThemePath(const String&); 211 206 String themePath() { return m_themePath; } 207 212 208 protected: 213 209 static float defaultFontSize; 214 210 215 211 private: 216 void createCanvas(); 217 void createEdje(); 218 void applyEdjeColors(); 219 void applyPartDescriptions(); 212 bool loadTheme(); 213 ALWAYS_INLINE bool loadThemeIfNeeded() const 214 { 215 return m_edje || const_cast<RenderThemeEfl*>(this)->loadTheme(); 216 } 217 218 void applyPartDescriptionsFrom(Evas_Object*); 219 220 220 const char* edjeGroupFromFormType(FormType) const; 221 221 void applyEdjeStateFromForm(Evas_Object*, ControlStates);
Note: See TracChangeset
for help on using the changeset viewer.