Changeset 187961 in webkit
- Timestamp:
- Aug 5, 2015 9:03:06 AM (9 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r187935 r187961 1 2015-08-04 Wenson Hsieh <wenson_hsieh@apple.com> 2 3 Checkboxes and radio buttons should scale when zooming or pinching to zoom 4 https://bugs.webkit.org/show_bug.cgi?id=147405 5 6 Reviewed by Dean Jackson. 7 8 Refactors paintButton and paintToggleButton to use a temporary buffer when rendering 9 if the controls are zoomed. This affects checkboxes, radio buttons, and normal (push) 10 buttons. 11 12 * platform/mac/ThemeMac.h: 13 * platform/mac/ThemeMac.mm: 14 (WebCore::paintToggleButton): Refactored to use drawCellOrFocusRingWithViewIntoContext. 15 (WebCore::paintButton): Refactored to use drawCellOrFocusRingWithViewIntoContext. 16 (WebCore::ThemeMac::drawCellOrFocusRingWithViewIntoContext): Draws a given button cell 17 and/or its focus ring into the given context, optionally using an offscreen buffer. 18 This is a static function in ThemeMac so it can be accessed later on by 19 RenderThemeMac when painting search fields that scale with zoom. 20 (WebCore::ThemeMac::paint): 21 (WebCore::buttonFocusRectOutlineWidth): Deleted. Made this value into a const float. 22 1 23 2015-08-04 Doug Russell <d_russell@apple.com> 2 24 -
trunk/Source/WebCore/platform/mac/ThemeMac.h
r187741 r187961 59 59 static NSView* ensuredView(ScrollView*, const ControlStates&, bool useUnparentedView = false); 60 60 static void setFocusRingClipRect(const FloatRect&); 61 static bool drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell>, GraphicsContext*, const FloatRect&, NSView*, bool /* drawButtonCell */, bool /* drawFocusRing */, bool /* useImageBuffer */, float /* deviceScaleFactor */); 61 62 }; 62 63 -
trunk/Source/WebCore/platform/mac/ThemeMac.mm
r187741 r187961 377 377 } 378 378 379 static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView )379 static void paintToggleButton(ControlPart buttonType, ControlStates& controlStates, GraphicsContext* context, const FloatRect& zoomedRect, float zoomFactor, ScrollView* scrollView, float deviceScaleFactor, float pageScaleFactor) 380 380 { 381 381 BEGIN_BLOCK_OBJC_EXCEPTIONS … … 426 426 NSView *view = ThemeMac::ensuredView(scrollView, controlStates, useUnparentedView); 427 427 428 bool isAnimating = false;429 428 bool needsRepaint = false; 429 bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f; 430 bool isCellFocused = controlStates.states() & ControlStates::FocusState; 430 431 431 432 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000 … … 436 437 437 438 [toggleButtonCell _renderCurrentAnimationFrameInContext:context->platformContext() atLocation:NSMakePoint(0, 0)]; 438 isAnimating = [toggleButtonCell _stateAnimationRunning]; 439 if (![toggleButtonCell _stateAnimationRunning] && isCellFocused) 440 needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, false, true, useImageBuffer, deviceScaleFactor); 439 441 } else 440 [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];442 needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor); 441 443 #else 442 [toggleButtonCell drawWithFrame:NSRect(inflatedRect) inView:view];444 needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(toggleButtonCell, context, inflatedRect, view, true, isCellFocused, useImageBuffer, deviceScaleFactor); 443 445 #endif 444 446 445 if (!isAnimating && (controlStates.states() & ControlStates::FocusState))446 needsRepaint = drawCellFocusRing(toggleButtonCell.get(), inflatedRect, view);447 447 [toggleButtonCell setControlView:nil]; 448 448 … … 519 519 setUpButtonCell(cell, part, controlStates, zoomedSize, zoomFactor); 520 520 return cell; 521 }522 523 static float buttonFocusRectOutlineWidth()524 {525 return 3.0f;526 521 } 527 522 … … 559 554 } 560 555 561 bool shouldUseImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f; 562 float focusThickness = buttonFocusRectOutlineWidth(); 563 564 std::unique_ptr<ImageBuffer> imageBuffer; 565 GraphicsContext* drawButtonContext = context; 566 if (shouldUseImageBuffer) { 567 imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(focusThickness, focusThickness), deviceScaleFactor, ColorSpaceDeviceRGB, context, false); 568 drawButtonContext = imageBuffer->context(); 569 } 570 LocalCurrentGraphicsContext localContext(drawButtonContext); 556 LocalCurrentGraphicsContext localContext(context); 571 557 572 558 NSView *view = ThemeMac::ensuredView(scrollView, controlStates); … … 574 560 NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell]; 575 561 562 bool useImageBuffer = pageScaleFactor != 1.0f || zoomFactor != 1.0f; 563 bool needsRepaint = ThemeMac::drawCellOrFocusRingWithViewIntoContext(buttonCell, context, inflatedRect, view, true, states & ControlStates::FocusState, useImageBuffer, deviceScaleFactor); 576 564 if (states & ControlStates::DefaultState) { 577 565 [window setDefaultButtonCell:buttonCell]; … … 581 569 } else if ([previousDefaultButtonCell isEqual:buttonCell]) 582 570 [window setDefaultButtonCell:nil]; 583 584 FloatRect drawFromImageBufferRect(focusThickness, focusThickness, inflatedRect.width(), inflatedRect.height()); 585 if (shouldUseImageBuffer) { 586 [buttonCell drawWithFrame:NSRect(drawFromImageBufferRect) inView:view]; 587 if (!(states & ControlStates::FocusState)) 588 context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness)); 589 } else 590 [buttonCell drawWithFrame:NSRect(inflatedRect) inView:view]; 591 592 if (states & ControlStates::FocusState) { 593 if (shouldUseImageBuffer) { 594 drawCellFocusRing(buttonCell, NSRect(drawFromImageBufferRect), view); 595 context->drawImageBuffer(imageBuffer.get(), ColorSpaceDeviceRGB, inflatedRect.location() - FloatSize(focusThickness, focusThickness)); 596 } else 597 drawCellFocusRing(buttonCell, NSRect(inflatedRect), view); 598 } 599 600 controlStates.setNeedsRepaint(false); 571 572 controlStates.setNeedsRepaint(needsRepaint); 601 573 602 574 [buttonCell setControlView:nil]; … … 689 661 { 690 662 focusRingClipRect = rect; 663 } 664 665 const float buttonFocusRectOutlineWidth = 3.0f; 666 667 bool ThemeMac::drawCellOrFocusRingWithViewIntoContext(RetainPtr<NSCell> cell, GraphicsContext* context, const FloatRect& inflatedRect, NSView* view, bool drawButtonCell, bool drawFocusRing, bool useImageBuffer, float deviceScaleFactor) 668 { 669 ASSERT(drawButtonCell || drawFocusRing); 670 bool needsRepaint = false; 671 if (useImageBuffer) { 672 NSRect imageBufferDrawRect = CGRectMake(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth, inflatedRect.width(), inflatedRect.height()); 673 std::unique_ptr<ImageBuffer> imageBuffer = ImageBuffer::createCompatibleBuffer(inflatedRect.size() + 2 * FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth), deviceScaleFactor, ColorSpaceSRGB, context, false); 674 { 675 LocalCurrentGraphicsContext localContext(imageBuffer->context()); 676 if (drawButtonCell) 677 [cell drawWithFrame:imageBufferDrawRect inView:view]; 678 679 if (drawFocusRing) 680 needsRepaint = drawCellFocusRing(cell.get(), imageBufferDrawRect, view); 681 } 682 context->drawImageBuffer(imageBuffer.get(), ColorSpaceSRGB, inflatedRect.location() - FloatSize(buttonFocusRectOutlineWidth, buttonFocusRectOutlineWidth)); 683 return needsRepaint; 684 } 685 if (drawButtonCell) 686 [cell drawWithFrame:NSRect(inflatedRect) inView:view]; 687 688 if (drawFocusRing) 689 needsRepaint = drawCellFocusRing(cell.get(), NSRect(inflatedRect), view); 690 691 return needsRepaint; 691 692 } 692 693 … … 844 845 switch (part) { 845 846 case CheckboxPart: 846 paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView );847 paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor); 847 848 break; 848 849 case RadioPart: 849 paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView );850 paintToggleButton(part, states, context, zoomedRect, zoomFactor, scrollView, deviceScaleFactor, pageScaleFactor); 850 851 break; 851 852 case PushButtonPart:
Note: See TracChangeset
for help on using the changeset viewer.