Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: Source/core/layout/LayoutTheme.cpp

Issue 1102353008: Split ThemePainter out of LayoutTheme (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /** 1 /**
2 * This file is part of the theme implementation for form controls in WebCore. 2 * This file is part of the theme implementation for form controls in WebCore.
3 * 3 *
4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc. 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2012 Apple Computer, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 25 matching lines...) Expand all
36 #include "core/html/HTMLDataListOptionsCollection.h" 36 #include "core/html/HTMLDataListOptionsCollection.h"
37 #include "core/html/HTMLFormControlElement.h" 37 #include "core/html/HTMLFormControlElement.h"
38 #include "core/html/HTMLInputElement.h" 38 #include "core/html/HTMLInputElement.h"
39 #include "core/html/HTMLMeterElement.h" 39 #include "core/html/HTMLMeterElement.h"
40 #include "core/html/HTMLOptionElement.h" 40 #include "core/html/HTMLOptionElement.h"
41 #include "core/html/parser/HTMLParserIdioms.h" 41 #include "core/html/parser/HTMLParserIdioms.h"
42 #include "core/html/shadow/MediaControlElements.h" 42 #include "core/html/shadow/MediaControlElements.h"
43 #include "core/html/shadow/ShadowElementNames.h" 43 #include "core/html/shadow/ShadowElementNames.h"
44 #include "core/html/shadow/SpinButtonElement.h" 44 #include "core/html/shadow/SpinButtonElement.h"
45 #include "core/html/shadow/TextControlInnerElements.h" 45 #include "core/html/shadow/TextControlInnerElements.h"
46 #include "core/layout/LayoutMeter.h"
47 #include "core/layout/LayoutView.h"
48 #include "core/style/AuthorStyleInfo.h" 46 #include "core/style/AuthorStyleInfo.h"
49 #include "core/style/ComputedStyle.h" 47 #include "core/style/ComputedStyle.h"
50 #include "core/page/FocusController.h" 48 #include "core/page/FocusController.h"
51 #include "core/page/Page.h" 49 #include "core/page/Page.h"
52 #include "core/paint/PaintInfo.h"
53 #include "platform/FileMetadata.h" 50 #include "platform/FileMetadata.h"
54 #include "platform/FloatConversion.h" 51 #include "platform/FloatConversion.h"
55 #include "platform/RuntimeEnabledFeatures.h" 52 #include "platform/RuntimeEnabledFeatures.h"
56 #include "platform/fonts/FontSelector.h" 53 #include "platform/fonts/FontSelector.h"
57 #include "platform/graphics/GraphicsContextStateSaver.h"
58 #include "platform/text/PlatformLocale.h" 54 #include "platform/text/PlatformLocale.h"
59 #include "platform/text/StringTruncator.h" 55 #include "platform/text/StringTruncator.h"
60 #include "public/platform/Platform.h" 56 #include "public/platform/Platform.h"
61 #include "public/platform/WebFallbackThemeEngine.h" 57 #include "public/platform/WebFallbackThemeEngine.h"
62 #include "public/platform/WebRect.h" 58 #include "public/platform/WebRect.h"
63 #include "wtf/text/StringBuilder.h" 59 #include "wtf/text/StringBuilder.h"
64 60
61 #if USE(NEW_THEME)
62 #include "platform/Theme.h"
63 #endif
64
65 // The methods in this file are shared by all themes on every platform. 65 // The methods in this file are shared by all themes on every platform.
66 66
67 namespace blink { 67 namespace blink {
68 68
69 using namespace HTMLNames; 69 using namespace HTMLNames;
70 70
71 static WebFallbackThemeEngine::State getWebFallbackThemeState(const LayoutTheme* theme, const LayoutObject* o)
72 {
73 if (!theme->isEnabled(o))
74 return WebFallbackThemeEngine::StateDisabled;
75 if (theme->isPressed(o))
76 return WebFallbackThemeEngine::StatePressed;
77 if (theme->isHovered(o))
78 return WebFallbackThemeEngine::StateHover;
79
80 return WebFallbackThemeEngine::StateNormal;
81 }
82
83 LayoutTheme::LayoutTheme() 71 LayoutTheme::LayoutTheme()
84 : m_hasCustomFocusRingColor(false) 72 : m_hasCustomFocusRingColor(false)
85 #if USE(NEW_THEME) 73 #if USE(NEW_THEME)
86 , m_platformTheme(platformTheme()) 74 , m_platformTheme(platformTheme())
87 #endif 75 #endif
88 { 76 {
89 } 77 }
90 78
91 void LayoutTheme::adjustStyle(ComputedStyle& style, Element* e, const AuthorStyl eInfo& authorStyle) 79 void LayoutTheme::adjustStyle(ComputedStyle& style, Element* e, const AuthorStyl eInfo& authorStyle)
92 { 80 {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 return adjustSearchFieldCancelButtonStyle(style, e); 213 return adjustSearchFieldCancelButtonStyle(style, e);
226 case SearchFieldDecorationPart: 214 case SearchFieldDecorationPart:
227 return adjustSearchFieldDecorationStyle(style, e); 215 return adjustSearchFieldDecorationStyle(style, e);
228 case SearchFieldResultsDecorationPart: 216 case SearchFieldResultsDecorationPart:
229 return adjustSearchFieldResultsDecorationStyle(style, e); 217 return adjustSearchFieldResultsDecorationStyle(style, e);
230 default: 218 default:
231 break; 219 break;
232 } 220 }
233 } 221 }
234 222
235 bool LayoutTheme::paint(LayoutObject* o, const PaintInfo& paintInfo, const IntRe ct& r)
236 {
237 ControlPart part = o->styleRef().appearance();
238
239 if (shouldUseFallbackTheme(o->styleRef()))
240 return paintUsingFallbackTheme(o, paintInfo, r);
241
242 #if USE(NEW_THEME)
243 switch (part) {
244 case CheckboxPart:
245 case RadioPart:
246 case PushButtonPart:
247 case SquareButtonPart:
248 case ButtonPart:
249 case InnerSpinButtonPart:
250 m_platformTheme->paint(part, controlStatesForRenderer(o), const_cast<Gra phicsContext*>(paintInfo.context), r, o->styleRef().effectiveZoom(), o->view()-> frameView());
251 return false;
252 default:
253 break;
254 }
255 #endif
256
257 // Call the appropriate paint method based off the appearance value.
258 switch (part) {
259 #if !USE(NEW_THEME)
260 case CheckboxPart:
261 return paintCheckbox(o, paintInfo, r);
262 case RadioPart:
263 return paintRadio(o, paintInfo, r);
264 case PushButtonPart:
265 case SquareButtonPart:
266 case ButtonPart:
267 return paintButton(o, paintInfo, r);
268 case InnerSpinButtonPart:
269 return paintInnerSpinButton(o, paintInfo, r);
270 #endif
271 case MenulistPart:
272 return paintMenuList(o, paintInfo, r);
273 case MeterPart:
274 case RelevancyLevelIndicatorPart:
275 case ContinuousCapacityLevelIndicatorPart:
276 case DiscreteCapacityLevelIndicatorPart:
277 case RatingLevelIndicatorPart:
278 return paintMeter(o, paintInfo, r);
279 case ProgressBarPart:
280 return paintProgressBar(o, paintInfo, r);
281 case SliderHorizontalPart:
282 case SliderVerticalPart:
283 return paintSliderTrack(o, paintInfo, r);
284 case SliderThumbHorizontalPart:
285 case SliderThumbVerticalPart:
286 return paintSliderThumb(o, paintInfo, r);
287 case MediaEnterFullscreenButtonPart:
288 case MediaExitFullscreenButtonPart:
289 return paintMediaFullscreenButton(o, paintInfo, r);
290 case MediaPlayButtonPart:
291 return paintMediaPlayButton(o, paintInfo, r);
292 case MediaOverlayPlayButtonPart:
293 return paintMediaOverlayPlayButton(o, paintInfo, r);
294 case MediaMuteButtonPart:
295 return paintMediaMuteButton(o, paintInfo, r);
296 case MediaToggleClosedCaptionsButtonPart:
297 return paintMediaToggleClosedCaptionsButton(o, paintInfo, r);
298 case MediaSliderPart:
299 return paintMediaSliderTrack(o, paintInfo, r);
300 case MediaSliderThumbPart:
301 return paintMediaSliderThumb(o, paintInfo, r);
302 case MediaVolumeSliderContainerPart:
303 return paintMediaVolumeSliderContainer(o, paintInfo, r);
304 case MediaVolumeSliderPart:
305 return paintMediaVolumeSliderTrack(o, paintInfo, r);
306 case MediaVolumeSliderThumbPart:
307 return paintMediaVolumeSliderThumb(o, paintInfo, r);
308 case MediaFullScreenVolumeSliderPart:
309 return paintMediaFullScreenVolumeSliderTrack(o, paintInfo, r);
310 case MediaFullScreenVolumeSliderThumbPart:
311 return paintMediaFullScreenVolumeSliderThumb(o, paintInfo, r);
312 case MediaTimeRemainingPart:
313 return paintMediaTimeRemaining(o, paintInfo, r);
314 case MediaCurrentTimePart:
315 return paintMediaCurrentTime(o, paintInfo, r);
316 case MediaControlsBackgroundPart:
317 return paintMediaControlsBackground(o, paintInfo, r);
318 case MediaCastOffButtonPart:
319 return paintMediaCastButton(o, paintInfo, r);
320 case MediaOverlayCastOffButtonPart:
321 return paintMediaCastButton(o, paintInfo, r);
322 case MenulistButtonPart:
323 case TextFieldPart:
324 case TextAreaPart:
325 return true;
326 case SearchFieldPart:
327 return paintSearchField(o, paintInfo, r);
328 case SearchFieldCancelButtonPart:
329 return paintSearchFieldCancelButton(o, paintInfo, r);
330 case SearchFieldDecorationPart:
331 return paintSearchFieldDecoration(o, paintInfo, r);
332 case SearchFieldResultsDecorationPart:
333 return paintSearchFieldResultsDecoration(o, paintInfo, r);
334 default:
335 break;
336 }
337
338 return true; // We don't support the appearance, so let the normal backgroun d/border paint.
339 }
340
341 bool LayoutTheme::paintBorderOnly(LayoutObject* o, const PaintInfo& paintInfo, c onst IntRect& r)
342 {
343 // Call the appropriate paint method based off the appearance value.
344 switch (o->style()->appearance()) {
345 case TextFieldPart:
346 return paintTextField(o, paintInfo, r);
347 case TextAreaPart:
348 return paintTextArea(o, paintInfo, r);
349 case MenulistButtonPart:
350 case SearchFieldPart:
351 case ListboxPart:
352 return true;
353 case CheckboxPart:
354 case RadioPart:
355 case PushButtonPart:
356 case SquareButtonPart:
357 case ButtonPart:
358 case MenulistPart:
359 case MeterPart:
360 case RelevancyLevelIndicatorPart:
361 case ContinuousCapacityLevelIndicatorPart:
362 case DiscreteCapacityLevelIndicatorPart:
363 case RatingLevelIndicatorPart:
364 case ProgressBarPart:
365 case SliderHorizontalPart:
366 case SliderVerticalPart:
367 case SliderThumbHorizontalPart:
368 case SliderThumbVerticalPart:
369 case SearchFieldCancelButtonPart:
370 case SearchFieldDecorationPart:
371 case SearchFieldResultsDecorationPart:
372 default:
373 break;
374 }
375
376 return false;
377 }
378
379 bool LayoutTheme::paintDecorations(LayoutObject* o, const PaintInfo& paintInfo, const IntRect& r)
380 {
381 // Call the appropriate paint method based off the appearance value.
382 switch (o->style()->appearance()) {
383 case MenulistButtonPart:
384 return paintMenuListButton(o, paintInfo, r);
385 case TextFieldPart:
386 case TextAreaPart:
387 case CheckboxPart:
388 case RadioPart:
389 case PushButtonPart:
390 case SquareButtonPart:
391 case ButtonPart:
392 case MenulistPart:
393 case MeterPart:
394 case RelevancyLevelIndicatorPart:
395 case ContinuousCapacityLevelIndicatorPart:
396 case DiscreteCapacityLevelIndicatorPart:
397 case RatingLevelIndicatorPart:
398 case ProgressBarPart:
399 case SliderHorizontalPart:
400 case SliderVerticalPart:
401 case SliderThumbHorizontalPart:
402 case SliderThumbVerticalPart:
403 case SearchFieldPart:
404 case SearchFieldCancelButtonPart:
405 case SearchFieldDecorationPart:
406 case SearchFieldResultsDecorationPart:
407 default:
408 break;
409 }
410
411 return false;
412 }
413
414 String LayoutTheme::extraDefaultStyleSheet() 223 String LayoutTheme::extraDefaultStyleSheet()
415 { 224 {
416 StringBuilder runtimeCSS; 225 StringBuilder runtimeCSS;
417 if (RuntimeEnabledFeatures::contextMenuEnabled()) 226 if (RuntimeEnabledFeatures::contextMenuEnabled())
418 runtimeCSS.appendLiteral("menu[type=\"popup\" i] { display: none; }"); 227 runtimeCSS.appendLiteral("menu[type=\"popup\" i] { display: none; }");
419 return runtimeCSS.toString(); 228 return runtimeCSS.toString();
420 } 229 }
421 230
231 static String formatChromiumMediaControlsTime(float time, float duration)
Xianzhu 2015/04/30 04:18:30 This is from LayoutMediaControls.cpp.
232 {
233 if (!std::isfinite(time))
234 time = 0;
235 if (!std::isfinite(duration))
236 duration = 0;
237 int seconds = static_cast<int>(fabsf(time));
238 int hours = seconds / (60 * 60);
239 int minutes = (seconds / 60) % 60;
240 seconds %= 60;
241
242 // duration defines the format of how the time is rendered
243 int durationSecs = static_cast<int>(fabsf(duration));
244 int durationHours = durationSecs / (60 * 60);
245 int durationMins = (durationSecs / 60) % 60;
246
247 if (durationHours || hours)
248 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
249 if (durationMins > 9)
250 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, sec onds);
251
252 return String::format("%s%01d:%02d", (time < 0 ? "-" : ""), minutes, seconds );
253 }
254
422 String LayoutTheme::formatMediaControlsTime(float time) const 255 String LayoutTheme::formatMediaControlsTime(float time) const
423 { 256 {
Xianzhu 2015/04/30 04:18:30 Previously this was overridden in LayoutThemeDefau
424 if (!std::isfinite(time)) 257 return formatChromiumMediaControlsTime(time, time);
425 time = 0;
426 int seconds = (int)fabsf(time);
427 int hours = seconds / (60 * 60);
428 int minutes = (seconds / 60) % 60;
429 seconds %= 60;
430 if (hours) {
431 if (hours > 9)
432 return String::format("%s%02d:%02d:%02d", (time < 0 ? "-" : ""), hou rs, minutes, seconds);
433
434 return String::format("%s%01d:%02d:%02d", (time < 0 ? "-" : ""), hours, minutes, seconds);
435 }
436
437 return String::format("%s%02d:%02d", (time < 0 ? "-" : ""), minutes, seconds );
438 } 258 }
439 259
440 String LayoutTheme::formatMediaControlsCurrentTime(float currentTime, float /*du ration*/) const 260 String LayoutTheme::formatMediaControlsCurrentTime(float currentTime, float dura tion) const
441 { 261 {
442 return formatMediaControlsTime(currentTime); 262 return formatChromiumMediaControlsTime(currentTime, duration);
443 } 263 }
444 264
445 Color LayoutTheme::activeSelectionBackgroundColor() const 265 Color LayoutTheme::activeSelectionBackgroundColor() const
446 { 266 {
447 return platformActiveSelectionBackgroundColor().blendWithWhite(); 267 return platformActiveSelectionBackgroundColor().blendWithWhite();
448 } 268 }
449 269
450 Color LayoutTheme::inactiveSelectionBackgroundColor() const 270 Color LayoutTheme::inactiveSelectionBackgroundColor() const
451 { 271 {
452 return platformInactiveSelectionBackgroundColor().blendWithWhite(); 272 return platformInactiveSelectionBackgroundColor().blendWithWhite();
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 return style.boxShadow(); 393 return style.boxShadow();
574 394
575 default: 395 default:
576 return false; 396 return false;
577 } 397 }
578 } 398 }
579 399
580 void LayoutTheme::adjustPaintInvalidationRect(const LayoutObject* o, IntRect& r) 400 void LayoutTheme::adjustPaintInvalidationRect(const LayoutObject* o, IntRect& r)
581 { 401 {
582 #if USE(NEW_THEME) 402 #if USE(NEW_THEME)
583 m_platformTheme->inflateControlPaintRect(o->style()->appearance(), controlSt atesForRenderer(o), r, o->style()->effectiveZoom()); 403 m_platformTheme->inflateControlPaintRect(o->style()->appearance(), controlSt atesForLayoutObject(o), r, o->style()->effectiveZoom());
584 #endif 404 #endif
585 } 405 }
586 406
587 bool LayoutTheme::shouldDrawDefaultFocusRing(LayoutObject* renderer) const 407 bool LayoutTheme::shouldDrawDefaultFocusRing(LayoutObject* layoutObject) const
588 { 408 {
589 if (supportsFocusRing(renderer->styleRef())) 409 if (supportsFocusRing(layoutObject->styleRef()))
590 return false; 410 return false;
591 Node* node = renderer->node(); 411 Node* node = layoutObject->node();
592 if (!node) 412 if (!node)
593 return true; 413 return true;
594 if (!renderer->styleRef().hasAppearance() && !node->isLink()) 414 if (!layoutObject->styleRef().hasAppearance() && !node->isLink())
595 return true; 415 return true;
596 // We can't use LayoutTheme::isFocused because outline:auto might be 416 // We can't use LayoutTheme::isFocused because outline:auto might be
597 // specified to non-:focus rulesets. 417 // specified to non-:focus rulesets.
598 if (node->focused() && !node->shouldHaveFocusAppearance()) 418 if (node->focused() && !node->shouldHaveFocusAppearance())
599 return false; 419 return false;
600 return true; 420 return true;
601 } 421 }
602 422
603 bool LayoutTheme::supportsFocusRing(const ComputedStyle& style) const 423 bool LayoutTheme::supportsFocusRing(const ComputedStyle& style) const
604 { 424 {
605 return (style.hasAppearance() && style.appearance() != TextFieldPart && styl e.appearance() != TextAreaPart && style.appearance() != MenulistButtonPart && st yle.appearance() != ListboxPart); 425 return (style.hasAppearance() && style.appearance() != TextFieldPart && styl e.appearance() != TextAreaPart && style.appearance() != MenulistButtonPart && st yle.appearance() != ListboxPart);
606 } 426 }
607 427
608 bool LayoutTheme::stateChanged(LayoutObject* o, ControlState state) const 428 bool LayoutTheme::stateChanged(LayoutObject* o, ControlState state) const
609 { 429 {
610 // Default implementation assumes the controls don't respond to changes in : hover state 430 // Default implementation assumes the controls don't respond to changes in : hover state
611 if (state == HoverControlState && !supportsHover(o->styleRef())) 431 if (state == HoverControlState && !supportsHover(o->styleRef()))
612 return false; 432 return false;
613 433
614 // Assume pressed state is only responded to if the control is enabled. 434 // Assume pressed state is only responded to if the control is enabled.
615 if (state == PressedControlState && !isEnabled(o)) 435 if (state == PressedControlState && !isEnabled(o))
616 return false; 436 return false;
617 437
618 o->setShouldDoFullPaintInvalidation(); 438 o->setShouldDoFullPaintInvalidation();
619 return true; 439 return true;
620 } 440 }
621 441
622 ControlStates LayoutTheme::controlStatesForRenderer(const LayoutObject* o) const 442 ControlStates LayoutTheme::controlStatesForLayoutObject(const LayoutObject* o)
623 { 443 {
624 ControlStates result = 0; 444 ControlStates result = 0;
625 if (isHovered(o)) { 445 if (isHovered(o)) {
626 result |= HoverControlState; 446 result |= HoverControlState;
627 if (isSpinUpButtonPartHovered(o)) 447 if (isSpinUpButtonPartHovered(o))
628 result |= SpinUpControlState; 448 result |= SpinUpControlState;
629 } 449 }
630 if (isPressed(o)) { 450 if (isPressed(o)) {
631 result |= PressedControlState; 451 result |= PressedControlState;
632 if (isSpinUpButtonPartPressed(o)) 452 if (isSpinUpButtonPartPressed(o))
633 result |= SpinUpControlState; 453 result |= SpinUpControlState;
634 } 454 }
635 if (isFocused(o) && o->style()->outlineStyleIsAuto()) 455 if (isFocused(o) && o->style()->outlineStyleIsAuto())
636 result |= FocusControlState; 456 result |= FocusControlState;
637 if (isEnabled(o)) 457 if (isEnabled(o))
638 result |= EnabledControlState; 458 result |= EnabledControlState;
639 if (isChecked(o)) 459 if (isChecked(o))
640 result |= CheckedControlState; 460 result |= CheckedControlState;
641 if (isReadOnlyControl(o)) 461 if (isReadOnlyControl(o))
642 result |= ReadOnlyControlState; 462 result |= ReadOnlyControlState;
643 if (!isActive(o)) 463 if (!isActive(o))
644 result |= WindowInactiveControlState; 464 result |= WindowInactiveControlState;
645 if (isIndeterminate(o)) 465 if (isIndeterminate(o))
646 result |= IndeterminateControlState; 466 result |= IndeterminateControlState;
647 return result; 467 return result;
648 } 468 }
649 469
650 bool LayoutTheme::isActive(const LayoutObject* o) const 470 bool LayoutTheme::isActive(const LayoutObject* o)
651 { 471 {
652 Node* node = o->node(); 472 Node* node = o->node();
653 if (!node) 473 if (!node)
654 return false; 474 return false;
655 475
656 Page* page = node->document().page(); 476 Page* page = node->document().page();
657 if (!page) 477 if (!page)
658 return false; 478 return false;
659 479
660 return page->focusController().isActive(); 480 return page->focusController().isActive();
661 } 481 }
662 482
663 bool LayoutTheme::isChecked(const LayoutObject* o) const 483 bool LayoutTheme::isChecked(const LayoutObject* o)
664 { 484 {
665 if (!isHTMLInputElement(o->node())) 485 if (!isHTMLInputElement(o->node()))
666 return false; 486 return false;
667 return toHTMLInputElement(o->node())->shouldAppearChecked(); 487 return toHTMLInputElement(o->node())->shouldAppearChecked();
668 } 488 }
669 489
670 bool LayoutTheme::isIndeterminate(const LayoutObject* o) const 490 bool LayoutTheme::isIndeterminate(const LayoutObject* o)
671 { 491 {
672 if (!isHTMLInputElement(o->node())) 492 if (!isHTMLInputElement(o->node()))
673 return false; 493 return false;
674 return toHTMLInputElement(o->node())->shouldAppearIndeterminate(); 494 return toHTMLInputElement(o->node())->shouldAppearIndeterminate();
675 } 495 }
676 496
677 bool LayoutTheme::isEnabled(const LayoutObject* o) const 497 bool LayoutTheme::isEnabled(const LayoutObject* o)
678 { 498 {
679 Node* node = o->node(); 499 Node* node = o->node();
680 if (!node || !node->isElementNode()) 500 if (!node || !node->isElementNode())
681 return true; 501 return true;
682 return !toElement(node)->isDisabledFormControl(); 502 return !toElement(node)->isDisabledFormControl();
683 } 503 }
684 504
685 bool LayoutTheme::isFocused(const LayoutObject* o) const 505 bool LayoutTheme::isFocused(const LayoutObject* o)
686 { 506 {
687 Node* node = o->node(); 507 Node* node = o->node();
688 if (!node) 508 if (!node)
689 return false; 509 return false;
690 510
691 node = node->focusDelegate(); 511 node = node->focusDelegate();
692 Document& document = node->document(); 512 Document& document = node->document();
693 LocalFrame* frame = document.frame(); 513 LocalFrame* frame = document.frame();
694 return node == document.focusedElement() && node->focused() && node->shouldH aveFocusAppearance() && frame && frame->selection().isFocusedAndActive(); 514 return node == document.focusedElement() && node->focused() && node->shouldH aveFocusAppearance() && frame && frame->selection().isFocusedAndActive();
695 } 515 }
696 516
697 bool LayoutTheme::isPressed(const LayoutObject* o) const 517 bool LayoutTheme::isPressed(const LayoutObject* o)
698 { 518 {
699 if (!o->node()) 519 if (!o->node())
700 return false; 520 return false;
701 return o->node()->active(); 521 return o->node()->active();
702 } 522 }
703 523
704 bool LayoutTheme::isSpinUpButtonPartPressed(const LayoutObject* o) const 524 bool LayoutTheme::isSpinUpButtonPartPressed(const LayoutObject* o)
705 { 525 {
706 Node* node = o->node(); 526 Node* node = o->node();
707 if (!node || !node->active() || !node->isElementNode() 527 if (!node || !node->active() || !node->isElementNode()
708 || !toElement(node)->isSpinButtonElement()) 528 || !toElement(node)->isSpinButtonElement())
709 return false; 529 return false;
710 SpinButtonElement* element = toSpinButtonElement(node); 530 SpinButtonElement* element = toSpinButtonElement(node);
711 return element->upDownState() == SpinButtonElement::Up; 531 return element->upDownState() == SpinButtonElement::Up;
712 } 532 }
713 533
714 bool LayoutTheme::isReadOnlyControl(const LayoutObject* o) const 534 bool LayoutTheme::isReadOnlyControl(const LayoutObject* o)
715 { 535 {
716 Node* node = o->node(); 536 Node* node = o->node();
717 if (!node || !node->isElementNode() || !toElement(node)->isFormControlElemen t()) 537 if (!node || !node->isElementNode() || !toElement(node)->isFormControlElemen t())
718 return false; 538 return false;
719 HTMLFormControlElement* element = toHTMLFormControlElement(node); 539 HTMLFormControlElement* element = toHTMLFormControlElement(node);
720 return element->isReadOnly(); 540 return element->isReadOnly();
721 } 541 }
722 542
723 bool LayoutTheme::isHovered(const LayoutObject* o) const 543 bool LayoutTheme::isHovered(const LayoutObject* o)
724 { 544 {
725 Node* node = o->node(); 545 Node* node = o->node();
726 if (!node) 546 if (!node)
727 return false; 547 return false;
728 if (!node->isElementNode() || !toElement(node)->isSpinButtonElement()) 548 if (!node->isElementNode() || !toElement(node)->isSpinButtonElement())
729 return node->hovered(); 549 return node->hovered();
730 SpinButtonElement* element = toSpinButtonElement(node); 550 SpinButtonElement* element = toSpinButtonElement(node);
731 return element->hovered() && element->upDownState() != SpinButtonElement::In determinate; 551 return element->hovered() && element->upDownState() != SpinButtonElement::In determinate;
732 } 552 }
733 553
734 bool LayoutTheme::isSpinUpButtonPartHovered(const LayoutObject* o) const 554 bool LayoutTheme::isSpinUpButtonPartHovered(const LayoutObject* o)
735 { 555 {
736 Node* node = o->node(); 556 Node* node = o->node();
737 if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement ()) 557 if (!node || !node->isElementNode() || !toElement(node)->isSpinButtonElement ())
738 return false; 558 return false;
739 SpinButtonElement* element = toSpinButtonElement(node); 559 SpinButtonElement* element = toSpinButtonElement(node);
740 return element->upDownState() == SpinButtonElement::Up; 560 return element->upDownState() == SpinButtonElement::Up;
741 } 561 }
742 562
743 #if !USE(NEW_THEME) 563 #if !USE(NEW_THEME)
744 564
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 IntSize LayoutTheme::meterSizeForBounds(const LayoutMeter*, const IntRect& bound s) const 608 IntSize LayoutTheme::meterSizeForBounds(const LayoutMeter*, const IntRect& bound s) const
789 { 609 {
790 return bounds.size(); 610 return bounds.size();
791 } 611 }
792 612
793 bool LayoutTheme::supportsMeter(ControlPart) const 613 bool LayoutTheme::supportsMeter(ControlPart) const
794 { 614 {
795 return false; 615 return false;
796 } 616 }
797 617
798 bool LayoutTheme::paintMeter(LayoutObject*, const PaintInfo&, const IntRect&)
799 {
800 return true;
801 }
802
803 void LayoutTheme::paintSliderTicks(LayoutObject* o, const PaintInfo& paintInfo, const IntRect& rect)
804 {
805 Node* node = o->node();
806 if (!isHTMLInputElement(node))
807 return;
808
809 HTMLInputElement* input = toHTMLInputElement(node);
810 if (input->type() != InputTypeNames::range)
811 return;
812
813 HTMLDataListElement* dataList = input->dataList();
814 if (!dataList)
815 return;
816
817 double min = input->minimum();
818 double max = input->maximum();
819 ControlPart part = o->style()->appearance();
820 // We don't support ticks on alternate sliders like MediaVolumeSliders.
821 if (part != SliderHorizontalPart && part != SliderVerticalPart)
822 return;
823 bool isHorizontal = part == SliderHorizontalPart;
824
825 IntSize thumbSize;
826 LayoutObject* thumbRenderer = input->userAgentShadowRoot()->getElementById(S hadowElementNames::sliderThumb())->layoutObject();
827 if (thumbRenderer) {
828 const ComputedStyle& thumbStyle = thumbRenderer->styleRef();
829 int thumbWidth = thumbStyle.width().intValue();
830 int thumbHeight = thumbStyle.height().intValue();
831 thumbSize.setWidth(isHorizontal ? thumbWidth : thumbHeight);
832 thumbSize.setHeight(isHorizontal ? thumbHeight : thumbWidth);
833 }
834
835 IntSize tickSize = sliderTickSize();
836 float zoomFactor = o->style()->effectiveZoom();
837 FloatRect tickRect;
838 int tickRegionSideMargin = 0;
839 int tickRegionWidth = 0;
840 IntRect trackBounds;
841 LayoutObject* trackRenderer = input->userAgentShadowRoot()->getElementById(S hadowElementNames::sliderTrack())->layoutObject();
842 // We can ignoring transforms because transform is handled by the graphics c ontext.
843 if (trackRenderer)
844 trackBounds = trackRenderer->absoluteBoundingBoxRectIgnoringTransforms() ;
845 IntRect sliderBounds = o->absoluteBoundingBoxRectIgnoringTransforms();
846
847 // Make position relative to the transformed ancestor element.
848 trackBounds.setX(trackBounds.x() - sliderBounds.x() + rect.x());
849 trackBounds.setY(trackBounds.y() - sliderBounds.y() + rect.y());
850
851 if (isHorizontal) {
852 tickRect.setWidth(floor(tickSize.width() * zoomFactor));
853 tickRect.setHeight(floor(tickSize.height() * zoomFactor));
854 tickRect.setY(floor(rect.y() + rect.height() / 2.0 + sliderTickOffsetFro mTrackCenter() * zoomFactor));
855 tickRegionSideMargin = trackBounds.x() + (thumbSize.width() - tickSize.w idth() * zoomFactor) / 2.0;
856 tickRegionWidth = trackBounds.width() - thumbSize.width();
857 } else {
858 tickRect.setWidth(floor(tickSize.height() * zoomFactor));
859 tickRect.setHeight(floor(tickSize.width() * zoomFactor));
860 tickRect.setX(floor(rect.x() + rect.width() / 2.0 + sliderTickOffsetFrom TrackCenter() * zoomFactor));
861 tickRegionSideMargin = trackBounds.y() + (thumbSize.width() - tickSize.w idth() * zoomFactor) / 2.0;
862 tickRegionWidth = trackBounds.height() - thumbSize.width();
863 }
864 RefPtrWillBeRawPtr<HTMLDataListOptionsCollection> options = dataList->option s();
865 for (unsigned i = 0; HTMLOptionElement* optionElement = options->item(i); i+ +) {
866 String value = optionElement->value();
867 if (!input->isValidValue(value))
868 continue;
869 double parsedValue = parseToDoubleForNumberType(input->sanitizeValue(val ue));
870 double tickFraction = (parsedValue - min) / (max - min);
871 double tickRatio = isHorizontal && o->style()->isLeftToRightDirection() ? tickFraction : 1.0 - tickFraction;
872 double tickPosition = round(tickRegionSideMargin + tickRegionWidth * tic kRatio);
873 if (isHorizontal)
874 tickRect.setX(tickPosition);
875 else
876 tickRect.setY(tickPosition);
877 paintInfo.context->fillRect(tickRect, o->resolveColor(CSSPropertyColor)) ;
878 }
879 }
880
881 double LayoutTheme::animationRepeatIntervalForProgressBar() const 618 double LayoutTheme::animationRepeatIntervalForProgressBar() const
882 { 619 {
883 return 0; 620 return 0;
884 } 621 }
885 622
886 double LayoutTheme::animationDurationForProgressBar() const 623 double LayoutTheme::animationDurationForProgressBar() const
887 { 624 {
888 return 0; 625 return 0;
889 } 626 }
890 627
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 switch (part) { 873 switch (part) {
1137 case CheckboxPart: 874 case CheckboxPart:
1138 return adjustCheckboxStyleUsingFallbackTheme(style, e); 875 return adjustCheckboxStyleUsingFallbackTheme(style, e);
1139 case RadioPart: 876 case RadioPart:
1140 return adjustRadioStyleUsingFallbackTheme(style, e); 877 return adjustRadioStyleUsingFallbackTheme(style, e);
1141 default: 878 default:
1142 break; 879 break;
1143 } 880 }
1144 } 881 }
1145 882
1146 bool LayoutTheme::paintUsingFallbackTheme(LayoutObject* o, const PaintInfo& i, c onst IntRect& r)
1147 {
1148 ControlPart part = o->style()->appearance();
1149 switch (part) {
1150 case CheckboxPart:
1151 return paintCheckboxUsingFallbackTheme(o, i, r);
1152 case RadioPart:
1153 return paintRadioUsingFallbackTheme(o, i, r);
1154 default:
1155 break;
1156 }
1157 return true;
1158 }
1159
1160 // static 883 // static
1161 void LayoutTheme::setSizeIfAuto(ComputedStyle& style, const IntSize& size) 884 void LayoutTheme::setSizeIfAuto(ComputedStyle& style, const IntSize& size)
1162 { 885 {
1163 if (style.width().isIntrinsicOrAuto()) 886 if (style.width().isIntrinsicOrAuto())
1164 style.setWidth(Length(size.width(), Fixed)); 887 style.setWidth(Length(size.width(), Fixed));
1165 if (style.height().isAuto()) 888 if (style.height().isAuto())
1166 style.setHeight(Length(size.height(), Fixed)); 889 style.setHeight(Length(size.height(), Fixed));
1167 } 890 }
1168 891
1169 bool LayoutTheme::paintCheckboxUsingFallbackTheme(LayoutObject* o, const PaintIn fo& i, const IntRect& r)
1170 {
1171 WebFallbackThemeEngine::ExtraParams extraParams;
1172 WebCanvas* canvas = i.context->canvas();
1173 extraParams.button.checked = isChecked(o);
1174 extraParams.button.indeterminate = isIndeterminate(o);
1175
1176 float zoomLevel = o->style()->effectiveZoom();
1177 GraphicsContextStateSaver stateSaver(*i.context);
1178 IntRect unzoomedRect = r;
1179 if (zoomLevel != 1) {
1180 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1181 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1182 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1183 i.context->scale(zoomLevel, zoomLevel);
1184 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1185 }
1186
1187 Platform::current()->fallbackThemeEngine()->paint(canvas, WebFallbackThemeEn gine::PartCheckbox, getWebFallbackThemeState(this, o), WebRect(unzoomedRect), &e xtraParams);
1188 return false;
1189 }
1190
1191 void LayoutTheme::adjustCheckboxStyleUsingFallbackTheme(ComputedStyle& style, El ement*) const 892 void LayoutTheme::adjustCheckboxStyleUsingFallbackTheme(ComputedStyle& style, El ement*) const
1192 { 893 {
1193 // If the width and height are both specified, then we have nothing to do. 894 // If the width and height are both specified, then we have nothing to do.
1194 if (!style.width().isIntrinsicOrAuto() && !style.height().isAuto()) 895 if (!style.width().isIntrinsicOrAuto() && !style.height().isAuto())
1195 return; 896 return;
1196 897
1197 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallba ckThemeEngine::PartCheckbox); 898 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallba ckThemeEngine::PartCheckbox);
1198 float zoomLevel = style.effectiveZoom(); 899 float zoomLevel = style.effectiveZoom();
1199 size.setWidth(size.width() * zoomLevel); 900 size.setWidth(size.width() * zoomLevel);
1200 size.setHeight(size.height() * zoomLevel); 901 size.setHeight(size.height() * zoomLevel);
1201 setSizeIfAuto(style, size); 902 setSizeIfAuto(style, size);
1202 903
1203 // padding - not honored by WinIE, needs to be removed. 904 // padding - not honored by WinIE, needs to be removed.
1204 style.resetPadding(); 905 style.resetPadding();
1205 906
1206 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme) 907 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1207 // for now, we will not honor it. 908 // for now, we will not honor it.
1208 style.resetBorder(); 909 style.resetBorder();
1209 } 910 }
1210 911
1211 bool LayoutTheme::paintRadioUsingFallbackTheme(LayoutObject* o, const PaintInfo& i, const IntRect& r)
1212 {
1213 WebFallbackThemeEngine::ExtraParams extraParams;
1214 WebCanvas* canvas = i.context->canvas();
1215 extraParams.button.checked = isChecked(o);
1216 extraParams.button.indeterminate = isIndeterminate(o);
1217
1218 float zoomLevel = o->style()->effectiveZoom();
1219 GraphicsContextStateSaver stateSaver(*i.context);
1220 IntRect unzoomedRect = r;
1221 if (zoomLevel != 1) {
1222 unzoomedRect.setWidth(unzoomedRect.width() / zoomLevel);
1223 unzoomedRect.setHeight(unzoomedRect.height() / zoomLevel);
1224 i.context->translate(unzoomedRect.x(), unzoomedRect.y());
1225 i.context->scale(zoomLevel, zoomLevel);
1226 i.context->translate(-unzoomedRect.x(), -unzoomedRect.y());
1227 }
1228
1229 Platform::current()->fallbackThemeEngine()->paint(canvas, WebFallbackThemeEn gine::PartRadio, getWebFallbackThemeState(this, o), WebRect(unzoomedRect), &extr aParams);
1230 return false;
1231 }
1232
1233 void LayoutTheme::adjustRadioStyleUsingFallbackTheme(ComputedStyle& style, Eleme nt*) const 912 void LayoutTheme::adjustRadioStyleUsingFallbackTheme(ComputedStyle& style, Eleme nt*) const
1234 { 913 {
1235 // If the width and height are both specified, then we have nothing to do. 914 // If the width and height are both specified, then we have nothing to do.
1236 if (!style.width().isIntrinsicOrAuto() && !style.height().isAuto()) 915 if (!style.width().isIntrinsicOrAuto() && !style.height().isAuto())
1237 return; 916 return;
1238 917
1239 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallba ckThemeEngine::PartRadio); 918 IntSize size = Platform::current()->fallbackThemeEngine()->getSize(WebFallba ckThemeEngine::PartRadio);
1240 float zoomLevel = style.effectiveZoom(); 919 float zoomLevel = style.effectiveZoom();
1241 size.setWidth(size.width() * zoomLevel); 920 size.setWidth(size.width() * zoomLevel);
1242 size.setHeight(size.height() * zoomLevel); 921 size.setHeight(size.height() * zoomLevel);
1243 setSizeIfAuto(style, size); 922 setSizeIfAuto(style, size);
1244 923
1245 // padding - not honored by WinIE, needs to be removed. 924 // padding - not honored by WinIE, needs to be removed.
1246 style.resetPadding(); 925 style.resetPadding();
1247 926
1248 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme) 927 // border - honored by WinIE, but looks terrible (just paints in the control box and turns off the Windows XP theme)
1249 // for now, we will not honor it. 928 // for now, we will not honor it.
1250 style.resetBorder(); 929 style.resetBorder();
1251 } 930 }
1252 931
1253 } // namespace blink 932 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698