1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "webkit/glue/webthemeengine_impl_linux.h" 6 7 #include "skia/ext/platform_canvas.h" 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRect.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h" 10 #include "ui/gfx/native_theme.h" 11 12 using WebKit::WebCanvas; 13 using WebKit::WebColor; 14 using WebKit::WebRect; 15 16 namespace webkit_glue { 17 18 static gfx::Rect WebRectToRect(const WebRect& rect) { 19 return gfx::Rect(rect.x, rect.y, rect.width, rect.height); 20 } 21 22 static gfx::NativeTheme::Part NativeThemePart( 23 WebKit::WebThemeEngine::Part part) { 24 switch (part) { 25 case WebKit::WebThemeEngine::PartScrollbarDownArrow: 26 return gfx::NativeTheme::kScrollbarDownArrow; 27 case WebKit::WebThemeEngine::PartScrollbarLeftArrow: 28 return gfx::NativeTheme::kScrollbarLeftArrow; 29 case WebKit::WebThemeEngine::PartScrollbarRightArrow: 30 return gfx::NativeTheme::kScrollbarRightArrow; 31 case WebKit::WebThemeEngine::PartScrollbarUpArrow: 32 return gfx::NativeTheme::kScrollbarUpArrow; 33 case WebKit::WebThemeEngine::PartScrollbarHorizontalThumb: 34 return gfx::NativeTheme::kScrollbarHorizontalThumb; 35 case WebKit::WebThemeEngine::PartScrollbarVerticalThumb: 36 return gfx::NativeTheme::kScrollbarVerticalThumb; 37 case WebKit::WebThemeEngine::PartScrollbarHorizontalTrack: 38 return gfx::NativeTheme::kScrollbarHorizontalTrack; 39 case WebKit::WebThemeEngine::PartScrollbarVerticalTrack: 40 return gfx::NativeTheme::kScrollbarVerticalTrack; 41 case WebKit::WebThemeEngine::PartCheckbox: 42 return gfx::NativeTheme::kCheckbox; 43 case WebKit::WebThemeEngine::PartRadio: 44 return gfx::NativeTheme::kRadio; 45 case WebKit::WebThemeEngine::PartButton: 46 return gfx::NativeTheme::kPushButton; 47 case WebKit::WebThemeEngine::PartTextField: 48 return gfx::NativeTheme::kTextField; 49 case WebKit::WebThemeEngine::PartMenuList: 50 return gfx::NativeTheme::kMenuList; 51 case WebKit::WebThemeEngine::PartSliderTrack: 52 return gfx::NativeTheme::kSliderTrack; 53 case WebKit::WebThemeEngine::PartSliderThumb: 54 return gfx::NativeTheme::kSliderThumb; 55 case WebKit::WebThemeEngine::PartInnerSpinButton: 56 return gfx::NativeTheme::kInnerSpinButton; 57 case WebKit::WebThemeEngine::PartProgressBar: 58 return gfx::NativeTheme::kProgressBar; 59 default: 60 return gfx::NativeTheme::kScrollbarDownArrow; 61 } 62 } 63 64 static gfx::NativeTheme::State NativeThemeState( 65 WebKit::WebThemeEngine::State state) { 66 switch (state) { 67 case WebKit::WebThemeEngine::StateDisabled: 68 return gfx::NativeTheme::kDisabled; 69 case WebKit::WebThemeEngine::StateHover: 70 return gfx::NativeTheme::kHovered; 71 case WebKit::WebThemeEngine::StateNormal: 72 return gfx::NativeTheme::kNormal; 73 case WebKit::WebThemeEngine::StatePressed: 74 return gfx::NativeTheme::kPressed; 75 default: 76 return gfx::NativeTheme::kDisabled; 77 } 78 } 79 80 static void GetNativeThemeExtraParams( 81 WebKit::WebThemeEngine::Part part, 82 WebKit::WebThemeEngine::State state, 83 const WebKit::WebThemeEngine::ExtraParams* extra_params, 84 gfx::NativeTheme::ExtraParams* native_theme_extra_params) { 85 switch (part) { 86 case WebKit::WebThemeEngine::PartScrollbarHorizontalTrack: 87 case WebKit::WebThemeEngine::PartScrollbarVerticalTrack: 88 native_theme_extra_params->scrollbar_track.track_x = 89 extra_params->scrollbarTrack.trackX; 90 native_theme_extra_params->scrollbar_track.track_y = 91 extra_params->scrollbarTrack.trackY; 92 native_theme_extra_params->scrollbar_track.track_width = 93 extra_params->scrollbarTrack.trackWidth; 94 native_theme_extra_params->scrollbar_track.track_height = 95 extra_params->scrollbarTrack.trackHeight; 96 break; 97 case WebKit::WebThemeEngine::PartCheckbox: 98 native_theme_extra_params->button.checked = extra_params->button.checked; 99 native_theme_extra_params->button.indeterminate = 100 extra_params->button.indeterminate; 101 break; 102 case WebKit::WebThemeEngine::PartRadio: 103 native_theme_extra_params->button.checked = extra_params->button.checked; 104 break; 105 case WebKit::WebThemeEngine::PartButton: 106 native_theme_extra_params->button.is_default = 107 extra_params->button.isDefault; 108 native_theme_extra_params->button.has_border = 109 extra_params->button.hasBorder; 110 native_theme_extra_params->button.background_color = 111 extra_params->button.backgroundColor; 112 break; 113 case WebKit::WebThemeEngine::PartTextField: 114 native_theme_extra_params->text_field.is_text_area = 115 extra_params->textField.isTextArea; 116 native_theme_extra_params->text_field.is_listbox = 117 extra_params->textField.isListbox; 118 native_theme_extra_params->text_field.background_color = 119 extra_params->textField.backgroundColor; 120 break; 121 case WebKit::WebThemeEngine::PartMenuList: 122 native_theme_extra_params->menu_list.has_border = 123 extra_params->menuList.hasBorder; 124 native_theme_extra_params->menu_list.has_border_radius = 125 extra_params->menuList.hasBorderRadius; 126 native_theme_extra_params->menu_list.arrow_x = 127 extra_params->menuList.arrowX; 128 native_theme_extra_params->menu_list.arrow_y = 129 extra_params->menuList.arrowY; 130 native_theme_extra_params->menu_list.background_color = 131 extra_params->menuList.backgroundColor; 132 break; 133 case WebKit::WebThemeEngine::PartSliderTrack: 134 case WebKit::WebThemeEngine::PartSliderThumb: 135 native_theme_extra_params->slider.vertical = 136 extra_params->slider.vertical; 137 native_theme_extra_params->slider.in_drag = extra_params->slider.inDrag; 138 break; 139 case WebKit::WebThemeEngine::PartInnerSpinButton: 140 native_theme_extra_params->inner_spin.spin_up = 141 extra_params->innerSpin.spinUp; 142 native_theme_extra_params->inner_spin.read_only = 143 extra_params->innerSpin.readOnly; 144 break; 145 case WebKit::WebThemeEngine::PartProgressBar: 146 native_theme_extra_params->progress_bar.determinate = 147 extra_params->progressBar.determinate; 148 native_theme_extra_params->progress_bar.value_rect_x = 149 extra_params->progressBar.valueRectX; 150 native_theme_extra_params->progress_bar.value_rect_y = 151 extra_params->progressBar.valueRectY; 152 native_theme_extra_params->progress_bar.value_rect_width = 153 extra_params->progressBar.valueRectWidth; 154 native_theme_extra_params->progress_bar.value_rect_height = 155 extra_params->progressBar.valueRectHeight; 156 break; 157 default: 158 break; // Parts that have no extra params get here. 159 } 160 } 161 162 WebKit::WebSize WebThemeEngineImpl::getSize(WebKit::WebThemeEngine::Part part) { 163 return gfx::NativeTheme::instance()->GetPartSize(NativeThemePart(part)); 164 } 165 166 void WebThemeEngineImpl::paint( 167 WebKit::WebCanvas* canvas, 168 WebKit::WebThemeEngine::Part part, 169 WebKit::WebThemeEngine::State state, 170 const WebKit::WebRect& rect, 171 const WebKit::WebThemeEngine::ExtraParams* extra_params) { 172 gfx::NativeTheme::ExtraParams native_theme_extra_params; 173 GetNativeThemeExtraParams( 174 part, state, extra_params, &native_theme_extra_params); 175 gfx::NativeTheme::instance()->Paint( 176 canvas, 177 NativeThemePart(part), 178 NativeThemeState(state), 179 WebRectToRect(rect), 180 native_theme_extra_params); 181 } 182 } // namespace webkit_glue 183