| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "web/PopupMenuImpl.h" | 6 #include "web/PopupMenuImpl.h" |
| 7 | 7 |
| 8 #include "core/HTMLNames.h" | 8 #include "core/HTMLNames.h" |
| 9 #include "core/css/CSSFontSelector.h" | 9 #include "core/css/CSSFontSelector.h" |
| 10 #include "core/dom/ElementTraversal.h" | 10 #include "core/dom/ElementTraversal.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 CSSFontSelector::trace(visitor); | 156 CSSFontSelector::trace(visitor); |
| 157 CSSFontSelectorClient::trace(visitor); | 157 CSSFontSelectorClient::trace(visitor); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // ---------------------------------------------------------------- | 160 // ---------------------------------------------------------------- |
| 161 | 161 |
| 162 class PopupMenuImpl::ItemIterationContext { | 162 class PopupMenuImpl::ItemIterationContext { |
| 163 STACK_ALLOCATED(); | 163 STACK_ALLOCATED(); |
| 164 public: | 164 public: |
| 165 ItemIterationContext(const ComputedStyle& style, SharedBuffer* buffer) | 165 ItemIterationContext(const ComputedStyle& style, SharedBuffer* buffer) |
| 166 : m_direction(style.direction()) | 166 : m_baseStyle(style) |
| 167 , m_foregroundColor(style.visitedDependentColor(CSSPropertyColor)) | |
| 168 , m_backgroundColor(style.visitedDependentColor(CSSPropertyBackgroundCol
or)) | 167 , m_backgroundColor(style.visitedDependentColor(CSSPropertyBackgroundCol
or)) |
| 169 , m_textTransform(style.textTransform()) | |
| 170 , m_fontDescription(style.fontDescription()) | |
| 171 , m_listIndex(0) | 168 , m_listIndex(0) |
| 172 , m_isInGroup(false) | 169 , m_isInGroup(false) |
| 173 , m_buffer(buffer) | 170 , m_buffer(buffer) |
| 174 { | 171 { |
| 175 ASSERT(m_buffer); | 172 ASSERT(m_buffer); |
| 176 #if OS(LINUX) | 173 #if OS(LINUX) |
| 177 // On other platforms, the <option> background color is the same as the | 174 // On other platforms, the <option> background color is the same as the |
| 178 // <select> background color. On Linux, that makes the <option> | 175 // <select> background color. On Linux, that makes the <option> |
| 179 // background color very dark, so by default, try to use a lighter | 176 // background color very dark, so by default, try to use a lighter |
| 180 // background color for <option>s. | 177 // background color for <option>s. |
| 181 if (LayoutTheme::theme().systemColor(CSSValueButtonface) == m_background
Color) | 178 if (LayoutTheme::theme().systemColor(CSSValueButtonface) == m_background
Color) |
| 182 m_backgroundColor = LayoutTheme::theme().systemColor(CSSValueMenu); | 179 m_backgroundColor = LayoutTheme::theme().systemColor(CSSValueMenu); |
| 183 #endif | 180 #endif |
| 184 } | 181 } |
| 185 | 182 |
| 186 void serializeBaseStyle() | 183 void serializeBaseStyle() |
| 187 { | 184 { |
| 185 ASSERT(!m_isInGroup); |
| 188 PagePopupClient::addString("baseStyle: {", m_buffer); | 186 PagePopupClient::addString("baseStyle: {", m_buffer); |
| 189 addProperty("backgroundColor", m_backgroundColor.serialized(), m_buffer)
; | 187 addProperty("backgroundColor", m_backgroundColor.serialized(), m_buffer)
; |
| 190 addProperty("color", m_foregroundColor.serialized(), m_buffer); | 188 addProperty("color", baseStyle().visitedDependentColor(CSSPropertyColor)
.serialized(), m_buffer); |
| 191 addProperty("textTransform", String(textTransformToString(m_textTransfor
m)), m_buffer); | 189 addProperty("textTransform", String(textTransformToString(baseStyle().te
xtTransform())), m_buffer); |
| 192 addProperty("fontSize", fontSize(), m_buffer); | 190 addProperty("fontSize", baseFont().computedPixelSize(), m_buffer); |
| 193 addProperty("fontStyle", String(fontStyleToString(fontStyle())), m_buffe
r); | 191 addProperty("fontStyle", String(fontStyleToString(baseFont().style())),
m_buffer); |
| 194 addProperty("fontVariant", String(fontVariantToString(fontVariant())), m
_buffer); | 192 addProperty("fontVariant", String(fontVariantToString(baseFont().variant
())), m_buffer); |
| 195 | 193 |
| 196 PagePopupClient::addString("fontFamily: [", m_buffer); | 194 PagePopupClient::addString("fontFamily: [", m_buffer); |
| 197 for (const FontFamily* f = &fontFamily(); f; f = f->next()) { | 195 for (const FontFamily* f = &baseFont().family(); f; f = f->next()) { |
| 198 addJavaScriptString(f->family().string(), m_buffer); | 196 addJavaScriptString(f->family().string(), m_buffer); |
| 199 if (f->next()) | 197 if (f->next()) |
| 200 PagePopupClient::addString(",", m_buffer); | 198 PagePopupClient::addString(",", m_buffer); |
| 201 } | 199 } |
| 202 PagePopupClient::addString("]", m_buffer); | 200 PagePopupClient::addString("]", m_buffer); |
| 203 PagePopupClient::addString("},\n", m_buffer); | 201 PagePopupClient::addString("},\n", m_buffer); |
| 204 } | 202 } |
| 205 | 203 |
| 206 void startGroupChildren() | 204 Color backgroundColor() const { return m_isInGroup ? m_groupStyle->visitedDe
pendentColor(CSSPropertyBackgroundColor) : m_backgroundColor; } |
| 205 // Do not use baseStyle() for background-color, use backgroundColor() |
| 206 // instead. |
| 207 const ComputedStyle& baseStyle() { return m_isInGroup ? *m_groupStyle : m_ba
seStyle; } |
| 208 const FontDescription& baseFont() { return m_isInGroup ? m_groupStyle->fontD
escription() : m_baseStyle.fontDescription(); } |
| 209 void startGroupChildren(const ComputedStyle& groupStyle) |
| 207 { | 210 { |
| 208 ASSERT(!m_isInGroup); | 211 ASSERT(!m_isInGroup); |
| 209 PagePopupClient::addString("children: [", m_buffer); | 212 PagePopupClient::addString("children: [", m_buffer); |
| 210 m_isInGroup = true; | 213 m_isInGroup = true; |
| 214 m_groupStyle = &groupStyle; |
| 211 } | 215 } |
| 212 void finishGroupIfNecessary() | 216 void finishGroupIfNecessary() |
| 213 { | 217 { |
| 214 if (!m_isInGroup) | 218 if (!m_isInGroup) |
| 215 return; | 219 return; |
| 216 PagePopupClient::addString("],},\n", m_buffer); | 220 PagePopupClient::addString("],},\n", m_buffer); |
| 217 m_isInGroup = false; | 221 m_isInGroup = false; |
| 222 m_groupStyle = nullptr; |
| 218 } | 223 } |
| 219 | 224 |
| 220 int fontSize() const { return m_fontDescription.computedPixelSize(); } | 225 const ComputedStyle& m_baseStyle; |
| 221 FontStyle fontStyle() const { return m_fontDescription.style(); } | |
| 222 FontVariant fontVariant() const { return m_fontDescription.variant(); } | |
| 223 const FontFamily& fontFamily() const { return m_fontDescription.family(); } | |
| 224 | |
| 225 TextDirection m_direction; | |
| 226 Color m_foregroundColor; | |
| 227 Color m_backgroundColor; | 226 Color m_backgroundColor; |
| 228 ETextTransform m_textTransform; | 227 const ComputedStyle* m_groupStyle; |
| 229 const FontDescription& m_fontDescription; | |
| 230 | 228 |
| 231 unsigned m_listIndex; | 229 unsigned m_listIndex; |
| 232 bool m_isInGroup; | 230 bool m_isInGroup; |
| 233 SharedBuffer* m_buffer; | 231 SharedBuffer* m_buffer; |
| 234 }; | 232 }; |
| 235 | 233 |
| 236 // ---------------------------------------------------------------- | 234 // ---------------------------------------------------------------- |
| 237 | 235 |
| 238 PassRefPtrWillBeRawPtr<PopupMenuImpl> PopupMenuImpl::create(ChromeClientImpl* ch
romeClient, HTMLSelectElement& ownerElement) | 236 PassRefPtrWillBeRawPtr<PopupMenuImpl> PopupMenuImpl::create(ChromeClientImpl* ch
romeClient, HTMLSelectElement& ownerElement) |
| 239 { | 237 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 const ComputedStyle* style = m_ownerElement->itemComputedStyle(element); | 307 const ComputedStyle* style = m_ownerElement->itemComputedStyle(element); |
| 310 ASSERT(style); | 308 ASSERT(style); |
| 311 SharedBuffer* data = context.m_buffer; | 309 SharedBuffer* data = context.m_buffer; |
| 312 // TODO(tkent): We generate unnecessary "style: {\n},\n" even if no | 310 // TODO(tkent): We generate unnecessary "style: {\n},\n" even if no |
| 313 // additional style. | 311 // additional style. |
| 314 PagePopupClient::addString("style: {\n", data); | 312 PagePopupClient::addString("style: {\n", data); |
| 315 if (style->visibility() == HIDDEN) | 313 if (style->visibility() == HIDDEN) |
| 316 addProperty("visibility", String("hidden"), data); | 314 addProperty("visibility", String("hidden"), data); |
| 317 if (style->display() == NONE) | 315 if (style->display() == NONE) |
| 318 addProperty("display", String("none"), data); | 316 addProperty("display", String("none"), data); |
| 319 if (context.m_direction != style->direction()) | 317 const ComputedStyle& baseStyle = context.baseStyle(); |
| 318 if (baseStyle.direction() != style->direction()) |
| 320 addProperty("direction", String(style->direction() == RTL ? "rtl" : "ltr
"), data); | 319 addProperty("direction", String(style->direction() == RTL ? "rtl" : "ltr
"), data); |
| 321 if (isOverride(style->unicodeBidi())) | 320 if (isOverride(style->unicodeBidi())) |
| 322 addProperty("unicodeBidi", String("bidi-override"), data); | 321 addProperty("unicodeBidi", String("bidi-override"), data); |
| 323 Color foregroundColor = style->visitedDependentColor(CSSPropertyColor); | 322 Color foregroundColor = style->visitedDependentColor(CSSPropertyColor); |
| 324 if (context.m_foregroundColor != foregroundColor) | 323 if (baseStyle.visitedDependentColor(CSSPropertyColor) != foregroundColor) |
| 325 addProperty("color", foregroundColor.serialized(), data); | 324 addProperty("color", foregroundColor.serialized(), data); |
| 326 Color backgroundColor = style->visitedDependentColor(CSSPropertyBackgroundCo
lor); | 325 Color backgroundColor = style->visitedDependentColor(CSSPropertyBackgroundCo
lor); |
| 327 if (context.m_backgroundColor != backgroundColor && backgroundColor != Color
::transparent) | 326 if (context.backgroundColor() != backgroundColor && backgroundColor != Color
::transparent) |
| 328 addProperty("backgroundColor", backgroundColor.serialized(), data); | 327 addProperty("backgroundColor", backgroundColor.serialized(), data); |
| 328 const FontDescription& baseFont = context.baseFont(); |
| 329 const FontDescription& fontDescription = style->font().fontDescription(); | 329 const FontDescription& fontDescription = style->font().fontDescription(); |
| 330 if (context.fontSize() != fontDescription.computedPixelSize()) | 330 if (baseFont.computedPixelSize() != fontDescription.computedPixelSize()) |
| 331 addProperty("fontSize", fontDescription.computedPixelSize(), data); | 331 addProperty("fontSize", fontDescription.computedPixelSize(), data); |
| 332 // Our UA stylesheet has font-weight:normal for OPTION. | 332 // Our UA stylesheet has font-weight:normal for OPTION. |
| 333 if (FontWeightNormal != fontDescription.weight()) | 333 if (FontWeightNormal != fontDescription.weight()) |
| 334 addProperty("fontWeight", String(fontWeightToString(fontDescription.weig
ht())), data); | 334 addProperty("fontWeight", String(fontWeightToString(fontDescription.weig
ht())), data); |
| 335 if (context.fontFamily() != fontDescription.family()) { | 335 if (baseFont.family() != fontDescription.family()) { |
| 336 PagePopupClient::addString("fontFamily: [\n", data); | 336 PagePopupClient::addString("fontFamily: [\n", data); |
| 337 for (const FontFamily* f = &fontDescription.family(); f; f = f->next())
{ | 337 for (const FontFamily* f = &fontDescription.family(); f; f = f->next())
{ |
| 338 addJavaScriptString(f->family().string(), data); | 338 addJavaScriptString(f->family().string(), data); |
| 339 if (f->next()) | 339 if (f->next()) |
| 340 PagePopupClient::addString(",\n", data); | 340 PagePopupClient::addString(",\n", data); |
| 341 } | 341 } |
| 342 PagePopupClient::addString("],\n", data); | 342 PagePopupClient::addString("],\n", data); |
| 343 } | 343 } |
| 344 if (context.fontStyle() != fontDescription.style()) | 344 if (baseFont.style() != fontDescription.style()) |
| 345 addProperty("fontStyle", String(fontStyleToString(fontDescription.style(
))), data); | 345 addProperty("fontStyle", String(fontStyleToString(fontDescription.style(
))), data); |
| 346 if (context.fontVariant() != fontDescription.variant()) | 346 if (baseFont.variant() != fontDescription.variant()) |
| 347 addProperty("fontVariant", String(fontVariantToString(fontDescription.va
riant())), data); | 347 addProperty("fontVariant", String(fontVariantToString(fontDescription.va
riant())), data); |
| 348 if (context.m_textTransform != style->textTransform()) | 348 if (baseStyle.textTransform() != style->textTransform()) |
| 349 addProperty("textTransform", String(textTransformToString(style->textTra
nsform())), data); | 349 addProperty("textTransform", String(textTransformToString(style->textTra
nsform())), data); |
| 350 | 350 |
| 351 PagePopupClient::addString("},\n", data); | 351 PagePopupClient::addString("},\n", data); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void PopupMenuImpl::addOption(ItemIterationContext& context, HTMLOptionElement&
element) | 354 void PopupMenuImpl::addOption(ItemIterationContext& context, HTMLOptionElement&
element) |
| 355 { | 355 { |
| 356 SharedBuffer* data = context.m_buffer; | 356 SharedBuffer* data = context.m_buffer; |
| 357 PagePopupClient::addString("{", data); | 357 PagePopupClient::addString("{", data); |
| 358 addProperty("label", element.text(), data); | 358 addProperty("label", element.text(), data); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 371 void PopupMenuImpl::addOptGroup(ItemIterationContext& context, HTMLOptGroupEleme
nt& element) | 371 void PopupMenuImpl::addOptGroup(ItemIterationContext& context, HTMLOptGroupEleme
nt& element) |
| 372 { | 372 { |
| 373 SharedBuffer* data = context.m_buffer; | 373 SharedBuffer* data = context.m_buffer; |
| 374 PagePopupClient::addString("{\n", data); | 374 PagePopupClient::addString("{\n", data); |
| 375 PagePopupClient::addString("type: \"optgroup\",\n", data); | 375 PagePopupClient::addString("type: \"optgroup\",\n", data); |
| 376 addProperty("label", element.groupLabelText(), data); | 376 addProperty("label", element.groupLabelText(), data); |
| 377 addProperty("title", element.title(), data); | 377 addProperty("title", element.title(), data); |
| 378 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); | 378 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); |
| 379 addProperty("disabled", element.isDisabledFormControl(), data); | 379 addProperty("disabled", element.isDisabledFormControl(), data); |
| 380 addElementStyle(context, element); | 380 addElementStyle(context, element); |
| 381 context.startGroupChildren(); | 381 context.startGroupChildren(*m_ownerElement->itemComputedStyle(element)); |
| 382 // We should call ItemIterationContext::finishGroupIfNecessary() later. | 382 // We should call ItemIterationContext::finishGroupIfNecessary() later. |
| 383 } | 383 } |
| 384 | 384 |
| 385 void PopupMenuImpl::addSeparator(ItemIterationContext& context, HTMLHRElement& e
lement) | 385 void PopupMenuImpl::addSeparator(ItemIterationContext& context, HTMLHRElement& e
lement) |
| 386 { | 386 { |
| 387 SharedBuffer* data = context.m_buffer; | 387 SharedBuffer* data = context.m_buffer; |
| 388 PagePopupClient::addString("{\n", data); | 388 PagePopupClient::addString("{\n", data); |
| 389 PagePopupClient::addString("type: \"separator\",\n", data); | 389 PagePopupClient::addString("type: \"separator\",\n", data); |
| 390 addProperty("title", element.title(), data); | 390 addProperty("title", element.title(), data); |
| 391 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); | 391 addProperty("ariaLabel", element.fastGetAttribute(HTMLNames::aria_labelAttr)
, data); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 | 516 |
| 517 void PopupMenuImpl::disconnectClient() | 517 void PopupMenuImpl::disconnectClient() |
| 518 { | 518 { |
| 519 m_ownerElement = nullptr; | 519 m_ownerElement = nullptr; |
| 520 // Cannot be done during finalization, so instead done when the | 520 // Cannot be done during finalization, so instead done when the |
| 521 // layout object is destroyed and disconnected. | 521 // layout object is destroyed and disconnected. |
| 522 dispose(); | 522 dispose(); |
| 523 } | 523 } |
| 524 | 524 |
| 525 } // namespace blink | 525 } // namespace blink |
| OLD | NEW |