Changeset 58561 in webkit
- Timestamp:
- Apr 30, 2010 12:45:09 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r58559 r58561 1 2010-04-30 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Adele Peterson. 4 5 Mac implementation of outer-spin-button appearance, and anonymous 6 element generation for <input type=number>. 7 https://bugs.webkit.org/show_bug.cgi?id=32813 8 9 input-appearance-spinbutton.html checks the appearances of various 10 sizes of spin-buttons. input-appearance-spinbutton-size.html 11 checks a spin-button height is equal to or less than the 12 corresponding text field height. 13 14 * platform/mac/fast/forms/input-appearance-spinbutton-expected.checksum: Added. 15 * platform/mac/fast/forms/input-appearance-spinbutton-expected.png: Added. 16 * platform/mac/fast/forms/input-appearance-spinbutton-expected.txt: Added. 17 * platform/mac/fast/forms/input-appearance-spinbutton-size-expected.txt: Added. 18 * platform/mac/fast/forms/input-appearance-spinbutton-size.html: Added. 19 * platform/mac/fast/forms/input-appearance-spinbutton.html: Added. 20 1 21 2010-04-29 Kent Tamura <tkent@chromium.org> 2 22 -
trunk/WebCore/ChangeLog
r58560 r58561 1 2010-04-30 Kent Tamura <tkent@chromium.org> 2 3 Reviewed by Adele Peterson. 4 5 Mac implementation of outer-spin-button appearance, and anonymous 6 element generation for <input type=number>. 7 https://bugs.webkit.org/show_bug.cgi?id=32813 8 9 The implementation uses NSStepperCell. Like the other Mac 10 controls, it has only three candidates for sizes. 11 12 The editable block of an input element is shrunk, and the 13 anonymous block for a spin button is put on the right of the 14 editable block. 15 16 Tests: platform/mac/fast/forms/input-appearance-spinbutton-size.html 17 platform/mac/fast/forms/input-appearance-spinbutton.html 18 19 * dom/Element.cpp: 20 (WebCore::Element::pseudoStyleCacheIsInvalid): 21 * dom/InputElement.h: 22 (WebCore::InputElement::hasSpinButton): 23 * html/HTMLInputElement.h: 24 (WebCore::HTMLInputElement::hasSpinButton): Return true for NUMBER type. 25 * platform/mac/ThemeMac.mm: 26 (WebCore::sizeFromNSControlSize): Split the main part of sizeFromFont() 27 to this in order to use stepperControlSizeForFont() instead of 28 controlSizeForFont(). 29 (WebCore::sizeFromFont): Just calls sizeFromNSControlSize() with 30 sizeFromFont(). No behavior changes. 31 (WebCore::stepperSizes): Returns sizes for mini, small, and regular. 32 (WebCore::stepperControlSizeForFont): 33 Dedicated version of controlSizeForFont(). 34 (WebCore::stepper): Returns NSStepperCell object with specified settings. 35 (WebCore::paintStepper): 36 (WebCore::ThemeMac::controlSize): Support for OuterSpinButton. 37 (WebCore::ThemeMac::minimumControlSize): ditto. 38 (WebCore::ThemeMac::inflateControlPaintRect): ditto. 39 (WebCore::ThemeMac::paint): ditto. 40 * rendering/RenderBox.cpp: 41 (WebCore::RenderBox::paintBoxDecorations): 42 Move the content to paintBoxDecorationsWithSize(). 43 (WebCore::RenderBox::paintBoxDecorationsWithSize): 44 * rendering/RenderBox.h: Declare paintBoxDecorationsWithSize(). 45 * rendering/RenderTextControlSingleLine.cpp: 46 (WebCore::RenderTextControlSingleLine::~RenderTextControlSingleLine): 47 (WebCore::RenderTextControlSingleLine::paintBoxDecorations): 48 Call paintBoxDecorationsWithSize() with smaller width by decorationWidthRight(). 49 (WebCore::RenderTextControlSingleLine::addFocusRingRects): 50 Add a rectangle of which width is smaller by decorationWidthRight(). 51 (WebCore::RenderTextControlSingleLine::layout): 52 Adjust m_outerSpinButton position. 53 (WebCore::RenderTextControlSingleLine::styleDidChange): 54 (WebCore::RenderTextControlSingleLine::textBlockWidth): 55 (WebCore::RenderTextControlSingleLine::decorationWidthRight): 56 (WebCore::RenderTextControlSingleLine::preferredDecorationWidthRight): 57 (WebCore::RenderTextControlSingleLine::createSubtreeIfNeeded): 58 Creates an element for m_outerSpinButton if it is needed. 59 (WebCore::RenderTextControlSingleLine::createInnerTextStyle): 60 (WebCore::RenderTextControlSingleLine::createOuterSpinButtonStyle): 61 * rendering/RenderTextControlSingleLine.h: Declare new methods and m_outerSpinButton. 62 * rendering/RenderThemeMac.mm: 63 (WebCore::RenderThemeMac::adjustRepaintRect): Support for OuterSpinButton. 64 1 65 2010-04-29 Adam Barth <abarth@webkit.org> 2 66 -
trunk/WebCore/dom/InputElement.h
r52204 r58561 44 44 virtual bool isSearchField() const = 0; 45 45 virtual bool isTextField() const = 0; 46 virtual bool hasSpinButton() const { return false; } 46 47 47 48 virtual bool searchEventsShouldBeDispatched() const = 0; -
trunk/WebCore/html/HTMLInputElement.h
r56385 r58561 129 129 virtual bool isInputTypeHidden() const { return m_type == HIDDEN; } 130 130 virtual bool isPasswordField() const { return m_type == PASSWORD; } 131 virtual bool hasSpinButton() const { return m_type == NUMBER; } 131 132 132 133 bool checked() const { return m_checked; } -
trunk/WebCore/platform/mac/ThemeMac.mm
r58533 r58561 83 83 } 84 84 85 static LengthSize sizeFrom Font(const Font& font, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes)86 { 87 IntSize controlSize = sizes[ controlSizeForFont(font)];85 static LengthSize sizeFromNSControlSize(NSControlSize nsControlSize, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes) 86 { 87 IntSize controlSize = sizes[nsControlSize]; 88 88 if (zoomFactor != 1.0f) 89 89 controlSize = IntSize(controlSize.width() * zoomFactor, controlSize.height() * zoomFactor); … … 94 94 result.setHeight(Length(controlSize.height(), Fixed)); 95 95 return result; 96 } 97 98 static LengthSize sizeFromFont(const Font& font, const LengthSize& zoomedSize, float zoomFactor, const IntSize* sizes) 99 { 100 return sizeFromNSControlSize(controlSizeForFont(font), zoomedSize, zoomFactor, sizes); 96 101 } 97 102 … … 445 450 } 446 451 452 // Stepper 453 454 static const IntSize* stepperSizes() 455 { 456 static const IntSize sizes[3] = { IntSize(19, 27), IntSize(15, 22), IntSize(13, 15) }; 457 return sizes; 458 } 459 460 // We don't use controlSizeForFont() for steppers because the stepper height 461 // should be equal to or less than the corresponding text field height, 462 static NSControlSize stepperControlSizeForFont(const Font& font) 463 { 464 int fontSize = font.pixelSize(); 465 if (fontSize >= 18) 466 return NSRegularControlSize; 467 if (fontSize >= 13) 468 return NSSmallControlSize; 469 return NSMiniControlSize; 470 } 471 472 static NSStepperCell* stepper(ControlStates states, const IntRect& zoomedRect, float zoomFactor) 473 { 474 static NSStepperCell* cell = [[NSStepperCell alloc] init]; 475 setControlSize(cell, stepperSizes(), zoomedRect.size(), zoomFactor); 476 477 updateStates(cell, states); 478 if (states & PressedState && states & SpinUpState) { 479 // FIXME: There is no way to draw a NSSteperCell with the up button hilighted. 480 // Disables the hilight of the down button if the up button is pressed. 481 [cell setHighlighted:NO]; 482 } 483 return cell; 484 } 485 486 static void paintStepper(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) 487 { 488 NSStepperCell* cell = stepper(states, zoomedRect, zoomFactor); 489 490 context->save(); 491 NSControlSize controlSize = [cell controlSize]; 492 IntSize zoomedSize = stepperSizes()[controlSize]; 493 IntRect rect(zoomedRect); 494 495 if (zoomFactor != 1.0f) { 496 rect.setWidth(rect.width() / zoomFactor); 497 rect.setHeight(rect.height() / zoomFactor); 498 context->translate(rect.x(), rect.y()); 499 context->scale(FloatSize(zoomFactor, zoomFactor)); 500 context->translate(-rect.x(), -rect.y()); 501 } 502 503 BEGIN_BLOCK_OBJC_EXCEPTIONS 504 [cell drawWithFrame:NSRect(rect) inView:ThemeMac::ensuredView(scrollView)]; 505 [cell setControlView:nil]; 506 END_BLOCK_OBJC_EXCEPTIONS 507 508 context->restore(); 509 } 510 447 511 // This will ensure that we always return a valid NSView, even if ScrollView doesn't have an associated document NSView. 448 512 // If the ScrollView doesn't have an NSView, we will return a fake NSView whose sole purpose is to tell AppKit that it's flipped. … … 500 564 return sizeFromFont(font, LengthSize(zoomedSize.width(), Length()), zoomFactor, listButtonSizes()); 501 565 #endif 566 case InnerSpinButtonPart: 567 // We don't use inner spin buttons on Mac. 568 return LengthSize(Length(Fixed), Length(Fixed)); 569 case OuterSpinButtonPart: 570 if (!zoomedSize.width().isIntrinsicOrAuto() && !zoomedSize.height().isIntrinsicOrAuto()) 571 return zoomedSize; 572 return sizeFromNSControlSize(stepperControlSizeForFont(font), zoomedSize, zoomFactor, stepperSizes()); 502 573 default: 503 574 return zoomedSize; … … 513 584 case ListButtonPart: 514 585 return LengthSize(Length(0, Fixed), Length(static_cast<int>(15 * zoomFactor), Fixed)); 586 case InnerSpinButtonPart: 587 // We don't use inner spin buttons on Mac. 588 return LengthSize(Length(Fixed), Length(Fixed)); 589 case OuterSpinButtonPart: { 590 IntSize base = stepperSizes()[NSMiniControlSize]; 591 return LengthSize(Length(static_cast<int>(base.width() * zoomFactor), Fixed), 592 Length(static_cast<int>(base.height() * zoomFactor), Fixed)); 593 } 515 594 default: 516 595 return Theme::minimumControlSize(part, font, zoomFactor); … … 589 668 break; 590 669 } 670 case OuterSpinButtonPart: { 671 static const int stepperMargin[4] = { 0, 0, 0, 0}; 672 NSCell *cell = stepper(states, zoomedRect, zoomFactor); 673 NSControlSize controlSize = [cell controlSize]; 674 IntSize zoomedSize = stepperSizes()[controlSize]; 675 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 676 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 677 zoomedRect = inflateRect(zoomedRect, zoomedSize, stepperMargin, zoomFactor); 678 break; 679 } 591 680 default: 592 681 break; … … 611 700 paintButton(part, states, context, zoomedRect, zoomFactor, scrollView); 612 701 break; 702 case OuterSpinButtonPart: 703 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); 704 break; 613 705 default: 614 706 break; -
trunk/WebCore/rendering/RenderBox.cpp
r58177 r58561 630 630 } 631 631 632 int w = width(); 633 int h = height(); 634 632 return paintBoxDecorationsWithSize(paintInfo, tx, ty, width(), height()); 633 } 634 635 void RenderBox::paintBoxDecorationsWithSize(PaintInfo& paintInfo, int tx, int ty, int width, int height) 636 { 635 637 // border-fit can adjust where we paint our border and background. If set, we snugly fit our line box descendants. (The iChat 636 638 // balloon layout is an example of this). 637 borderFitAdjust(tx, w );639 borderFitAdjust(tx, width); 638 640 639 641 // FIXME: Should eventually give the theme control over whether the box shadow should paint, since controls could have 640 642 // custom shadows of their own. 641 paintBoxShadow(paintInfo.context, tx, ty, w , h, style(), Normal);643 paintBoxShadow(paintInfo.context, tx, ty, width, height, style(), Normal); 642 644 643 645 // If we have a native theme appearance, paint that before painting our background. 644 646 // The theme will tell us whether or not we should also paint the CSS background. 645 bool themePainted = style()->hasAppearance() && !theme()->paint(this, paintInfo, IntRect(tx, ty, w , h));647 bool themePainted = style()->hasAppearance() && !theme()->paint(this, paintInfo, IntRect(tx, ty, width, height)); 646 648 if (!themePainted) { 647 649 // The <body> only paints its background if the root element has defined a background … … 649 651 // since the root could be inline and wrapped in an anonymous block. 650 652 if (!isBody() || document()->documentElement()->renderer()->style()->hasBackground()) 651 paintFillLayers(paintInfo, style()->backgroundColor(), style()->backgroundLayers(), tx, ty, w , h);653 paintFillLayers(paintInfo, style()->backgroundColor(), style()->backgroundLayers(), tx, ty, width, height); 652 654 if (style()->hasAppearance()) 653 theme()->paintDecorations(this, paintInfo, IntRect(tx, ty, w , h));654 } 655 paintBoxShadow(paintInfo.context, tx, ty, w , h, style(), Inset);655 theme()->paintDecorations(this, paintInfo, IntRect(tx, ty, width, height)); 656 } 657 paintBoxShadow(paintInfo.context, tx, ty, width, height, style(), Inset); 656 658 657 659 // The theme will tell us whether or not we should also paint the CSS border. 658 if ((!style()->hasAppearance() || (!themePainted && theme()->paintBorderOnly(this, paintInfo, IntRect(tx, ty, w , h)))) && style()->hasBorder())659 paintBorder(paintInfo.context, tx, ty, w , h, style());660 if ((!style()->hasAppearance() || (!themePainted && theme()->paintBorderOnly(this, paintInfo, IntRect(tx, ty, width, height)))) && style()->hasBorder()) 661 paintBorder(paintInfo.context, tx, ty, width, height, style()); 660 662 } 661 663 -
trunk/WebCore/rendering/RenderBox.h
r56941 r58561 309 309 void paintFillLayers(const PaintInfo&, const Color&, const FillLayer*, int tx, int ty, int width, int height, CompositeOperator = CompositeSourceOver, RenderObject* backgroundObject = 0); 310 310 311 void paintBoxDecorationsWithSize(PaintInfo&, int tx, int ty, int width, int height); 311 312 void paintMaskImages(const PaintInfo&, int tx, int ty, int width, int height); 312 313 -
trunk/WebCore/rendering/RenderTextControlSingleLine.cpp
r58400 r58561 67 67 if (m_innerBlock) 68 68 m_innerBlock->detach(); 69 70 if (m_outerSpinButton) 71 m_outerSpinButton->detach(); 69 72 } 70 73 … … 192 195 } 193 196 197 void RenderTextControlSingleLine::paintBoxDecorations(PaintInfo& paintInfo, int tx, int ty) 198 { 199 paintBoxDecorationsWithSize(paintInfo, tx, ty, width() - decorationWidthRight(), height()); 200 } 201 202 void RenderTextControlSingleLine::addFocusRingRects(Vector<IntRect>& rects, int tx, int ty) 203 { 204 int w = width() - decorationWidthRight(); 205 if (w && height()) 206 rects.append(IntRect(tx, ty, w, height())); 207 } 208 194 209 void RenderTextControlSingleLine::layout() 195 210 { … … 237 252 if (currentHeight < height()) 238 253 childBlock->setLocation(childBlock->x(), (height() - currentHeight) / 2); 254 255 // Center the spin button vertically, and move it to the right by 256 // padding + border of the text fields. 257 if (RenderBox* spinBox = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { 258 int diff = height() - spinBox->height(); 259 // If the diff is odd, the top area over the spin button takes the 260 // remaining one pixel. It's good for Mac NSStepper because it has 261 // shadow at the bottom. 262 int y = (diff / 2) + (diff % 2); 263 spinBox->setLocation(spinBox->x() + paddingRight() + borderRight(), y); 264 } 239 265 } 240 266 … … 332 358 cancelRenderer->setStyle(createCancelButtonStyle(style())); 333 359 360 if (RenderObject* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderer() : 0) 361 spinRenderer->setStyle(createOuterSpinButtonStyle()); 362 334 363 setHasOverflowClip(false); 335 364 } … … 373 402 } 374 403 404 return width - decorationWidthRight(); 405 } 406 407 int RenderTextControlSingleLine::decorationWidthRight() const 408 { 409 int width = 0; 410 if (RenderBox* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { 411 spinRenderer->calcWidth(); 412 width += spinRenderer->width() + spinRenderer->marginLeft() + spinRenderer->marginRight(); 413 } 414 if (width > 0) 415 width += paddingRight() + borderRight(); 375 416 return width; 376 417 } … … 422 463 } 423 464 465 int RenderTextControlSingleLine::preferredDecorationWidthRight() const 466 { 467 int width = 0; 468 if (RenderBox* spinRenderer = m_outerSpinButton ? m_outerSpinButton->renderBox() : 0) { 469 spinRenderer->calcWidth(); 470 width += spinRenderer->minPrefWidth() + spinRenderer->marginLeft() + spinRenderer->marginRight(); 471 } 472 if (width > 0) 473 width += paddingRight() + borderRight(); 474 return width; 475 } 476 424 477 void RenderTextControlSingleLine::adjustControlHeightBasedOnLineHeight(int lineHeight) 425 478 { … … 449 502 if (!inputElement()->isSearchField()) { 450 503 RenderTextControl::createSubtreeIfNeeded(m_innerBlock.get()); 504 if (inputElement()->hasSpinButton() && !m_outerSpinButton) { 505 // FIXME: Introduce a dedicated element for spin buttons. 506 m_outerSpinButton = new TextControlInnerElement(document(), node()); 507 m_outerSpinButton->attachInnerElement(node(), createOuterSpinButtonStyle(), renderArena()); 508 } 451 509 return; 452 510 } … … 525 583 textBlockStyle->setLineHeight(Length(-100.0f, Percent)); 526 584 527 textBlockStyle->setDisplay(m_innerBlock ? INLINE_BLOCK : BLOCK);585 textBlockStyle->setDisplay(m_innerBlock || inputElement()->hasSpinButton() ? INLINE_BLOCK : BLOCK); 528 586 529 587 // We're adding one extra pixel of padding to match WinIE. … … 595 653 cancelBlockStyle->setVisibility(visibilityForCancelButton()); 596 654 return cancelBlockStyle.release(); 655 } 656 657 PassRefPtr<RenderStyle> RenderTextControlSingleLine::createOuterSpinButtonStyle() const 658 { 659 ASSERT(node()->isHTMLElement()); 660 RefPtr<RenderStyle> buttonStyle = getCachedPseudoStyle(OUTER_SPIN_BUTTON); 661 if (!buttonStyle) 662 buttonStyle = RenderStyle::create(); 663 buttonStyle->inheritFrom(style()); 664 return buttonStyle.release(); 597 665 } 598 666 -
trunk/WebCore/rendering/RenderTextControlSingleLine.h
r58400 r58561 54 54 void capsLockStateMayHaveChanged(); 55 55 56 // Decoration width outside of the text field. 57 int decorationWidthRight() const; 58 56 59 private: 60 int preferredDecorationWidthRight() const; 57 61 virtual bool hasControlClip() const { return m_cancelButton; } 58 62 virtual bool isTextField() const { return true; } … … 60 64 virtual void subtreeHasChanged(); 61 65 virtual void paint(PaintInfo&, int tx, int ty); 66 virtual void paintBoxDecorations(PaintInfo&, int tx, int ty); 67 virtual void addFocusRingRects(Vector<IntRect>&, int tx, int ty); 62 68 virtual void layout(); 63 69 … … 90 96 PassRefPtr<RenderStyle> createResultsButtonStyle(const RenderStyle* startStyle) const; 91 97 PassRefPtr<RenderStyle> createCancelButtonStyle(const RenderStyle* startStyle) const; 98 PassRefPtr<RenderStyle> createOuterSpinButtonStyle() const; 92 99 93 100 void updateCancelButtonVisibility() const; … … 131 138 RefPtr<SearchFieldResultsButtonElement> m_resultsButton; 132 139 RefPtr<SearchFieldCancelButtonElement> m_cancelButton; 140 RefPtr<TextControlInnerElement> m_outerSpinButton; 133 141 134 142 Timer<RenderTextControlSingleLine> m_searchEventTimer; -
trunk/WebCore/rendering/RenderThemeMac.mm
r57844 r58561 488 488 case DefaultButtonPart: 489 489 case ButtonPart: 490 case OuterSpinButtonPart: 490 491 return RenderTheme::adjustRepaintRect(o, r); 491 492 default:
Note: See TracChangeset
for help on using the changeset viewer.