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

Side by Side Diff: Source/WebCore/platform/mac/ThemeMac.mm

Issue 11418042: Merge 134698 - [chromium/mac] Fix drawing of buttons, checkboxes, radio boxes, and steppers when th… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1312/
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « LayoutTests/platform/chromium/TestExpectations ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2010, 2011, 2012 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2010, 2011, 2012 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return checkboxCell; 262 return checkboxCell;
263 } 263 }
264 264
265 // FIXME: Share more code with radio buttons. 265 // FIXME: Share more code with radio buttons.
266 static void paintCheckbox(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) 266 static void paintCheckbox(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
267 { 267 {
268 BEGIN_BLOCK_OBJC_EXCEPTIONS 268 BEGIN_BLOCK_OBJC_EXCEPTIONS
269 269
270 // Determine the width and height needed for the control and prepare the cel l for painting. 270 // Determine the width and height needed for the control and prepare the cel l for painting.
271 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor); 271 NSButtonCell *checkboxCell = checkbox(states, zoomedRect, zoomFactor);
272 LocalCurrentGraphicsContext localContext(context);
273
274 GraphicsContextStateSaver stateSaver(*context); 272 GraphicsContextStateSaver stateSaver(*context);
275 273
276 NSControlSize controlSize = [checkboxCell controlSize]; 274 NSControlSize controlSize = [checkboxCell controlSize];
277 IntSize zoomedSize = checkboxSizes()[controlSize]; 275 IntSize zoomedSize = checkboxSizes()[controlSize];
278 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 276 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
279 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 277 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
280 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(c ontrolSize), zoomFactor); 278 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, checkboxMargins(c ontrolSize), zoomFactor);
281 279
282 if (zoomFactor != 1.0f) { 280 if (zoomFactor != 1.0f) {
283 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 281 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
284 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 282 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
285 context->translate(inflatedRect.x(), inflatedRect.y()); 283 context->translate(inflatedRect.x(), inflatedRect.y());
286 context->scale(FloatSize(zoomFactor, zoomFactor)); 284 context->scale(FloatSize(zoomFactor, zoomFactor));
287 context->translate(-inflatedRect.x(), -inflatedRect.y()); 285 context->translate(-inflatedRect.x(), -inflatedRect.y());
288 } 286 }
289 287
288 LocalCurrentGraphicsContext localContext(context);
290 NSView *view = ThemeMac::ensuredView(scrollView); 289 NSView *view = ThemeMac::ensuredView(scrollView);
291 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view]; 290 [checkboxCell drawWithFrame:NSRect(inflatedRect) inView:view];
292 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 291 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
293 if (states & FocusState) 292 if (states & FocusState)
294 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi ew]; 293 [checkboxCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:vi ew];
295 #endif 294 #endif
296 [checkboxCell setControlView:nil]; 295 [checkboxCell setControlView:nil];
297 296
298 END_BLOCK_OBJC_EXCEPTIONS 297 END_BLOCK_OBJC_EXCEPTIONS
299 } 298 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 // Update the various states we respond to. 342 // Update the various states we respond to.
344 updateStates(radioCell, states); 343 updateStates(radioCell, states);
345 344
346 return radioCell; 345 return radioCell;
347 } 346 }
348 347
349 static void paintRadio(ControlStates states, GraphicsContext* context, const Int Rect& zoomedRect, float zoomFactor, ScrollView* scrollView) 348 static void paintRadio(ControlStates states, GraphicsContext* context, const Int Rect& zoomedRect, float zoomFactor, ScrollView* scrollView)
350 { 349 {
351 // Determine the width and height needed for the control and prepare the cel l for painting. 350 // Determine the width and height needed for the control and prepare the cel l for painting.
352 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor); 351 NSButtonCell *radioCell = radio(states, zoomedRect, zoomFactor);
353 LocalCurrentGraphicsContext localContext(context);
354
355 GraphicsContextStateSaver stateSaver(*context); 352 GraphicsContextStateSaver stateSaver(*context);
356 353
357 NSControlSize controlSize = [radioCell controlSize]; 354 NSControlSize controlSize = [radioCell controlSize];
358 IntSize zoomedSize = radioSizes()[controlSize]; 355 IntSize zoomedSize = radioSizes()[controlSize];
359 zoomedSize.setWidth(zoomedSize.width() * zoomFactor); 356 zoomedSize.setWidth(zoomedSize.width() * zoomFactor);
360 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 357 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
361 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(cont rolSize), zoomFactor); 358 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, radioMargins(cont rolSize), zoomFactor);
362 359
363 if (zoomFactor != 1.0f) { 360 if (zoomFactor != 1.0f) {
364 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 361 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
365 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 362 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
366 context->translate(inflatedRect.x(), inflatedRect.y()); 363 context->translate(inflatedRect.x(), inflatedRect.y());
367 context->scale(FloatSize(zoomFactor, zoomFactor)); 364 context->scale(FloatSize(zoomFactor, zoomFactor));
368 context->translate(-inflatedRect.x(), -inflatedRect.y()); 365 context->translate(-inflatedRect.x(), -inflatedRect.y());
369 } 366 }
370 367
368 LocalCurrentGraphicsContext localContext(context);
371 BEGIN_BLOCK_OBJC_EXCEPTIONS 369 BEGIN_BLOCK_OBJC_EXCEPTIONS
372 NSView *view = ThemeMac::ensuredView(scrollView); 370 NSView *view = ThemeMac::ensuredView(scrollView);
373 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view]; 371 [radioCell drawWithFrame:NSRect(inflatedRect) inView:view];
374 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING 372 #if !BUTTON_CELL_DRAW_WITH_FRAME_DRAWS_FOCUS_RING
375 if (states & FocusState) 373 if (states & FocusState)
376 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view] ; 374 [radioCell _web_drawFocusRingWithFrame:NSRect(inflatedRect) inView:view] ;
377 #endif 375 #endif
378 [radioCell setControlView:nil]; 376 [radioCell setControlView:nil];
379 END_BLOCK_OBJC_EXCEPTIONS 377 END_BLOCK_OBJC_EXCEPTIONS
380 } 378 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor); 439 setUpButtonCell(cell, part, states, zoomedRect, zoomFactor);
442 return cell; 440 return cell;
443 } 441 }
444 442
445 static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView) 443 static void paintButton(ControlPart part, ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
446 { 444 {
447 BEGIN_BLOCK_OBJC_EXCEPTIONS 445 BEGIN_BLOCK_OBJC_EXCEPTIONS
448 446
449 // Determine the width and height needed for the control and prepare the cel l for painting. 447 // Determine the width and height needed for the control and prepare the cel l for painting.
450 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor); 448 NSButtonCell *buttonCell = button(part, states, zoomedRect, zoomFactor);
451 LocalCurrentGraphicsContext localContext(context); 449 GraphicsContextStateSaver stateSaver(*context);
452 450
453 NSControlSize controlSize = [buttonCell controlSize]; 451 NSControlSize controlSize = [buttonCell controlSize];
454 IntSize zoomedSize = buttonSizes()[controlSize]; 452 IntSize zoomedSize = buttonSizes()[controlSize];
455 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid th, so the zoomed width can just be honored. 453 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain wid th, so the zoomed width can just be honored.
456 zoomedSize.setHeight(zoomedSize.height() * zoomFactor); 454 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
457 IntRect inflatedRect = zoomedRect; 455 IntRect inflatedRect = zoomedRect;
458 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) { 456 if ([buttonCell bezelStyle] == NSRoundedBezelStyle) {
459 // Center the button within the available space. 457 // Center the button within the available space.
460 if (inflatedRect.height() > zoomedSize.height()) { 458 if (inflatedRect.height() > zoomedSize.height()) {
461 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2); 459 inflatedRect.setY(inflatedRect.y() + (inflatedRect.height() - zoomed Size.height()) / 2);
462 inflatedRect.setHeight(zoomedSize.height()); 460 inflatedRect.setHeight(zoomedSize.height());
463 } 461 }
464 462
465 // Now inflate it to account for the shadow. 463 // Now inflate it to account for the shadow.
466 inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(contr olSize), zoomFactor); 464 inflatedRect = inflateRect(inflatedRect, zoomedSize, buttonMargins(contr olSize), zoomFactor);
467 465
468 if (zoomFactor != 1.0f) { 466 if (zoomFactor != 1.0f) {
469 inflatedRect.setWidth(inflatedRect.width() / zoomFactor); 467 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
470 inflatedRect.setHeight(inflatedRect.height() / zoomFactor); 468 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
471 context->translate(inflatedRect.x(), inflatedRect.y()); 469 context->translate(inflatedRect.x(), inflatedRect.y());
472 context->scale(FloatSize(zoomFactor, zoomFactor)); 470 context->scale(FloatSize(zoomFactor, zoomFactor));
473 context->translate(-inflatedRect.x(), -inflatedRect.y()); 471 context->translate(-inflatedRect.x(), -inflatedRect.y());
474 } 472 }
475 } 473 }
476 474
475 LocalCurrentGraphicsContext localContext(context);
477 NSView *view = ThemeMac::ensuredView(scrollView); 476 NSView *view = ThemeMac::ensuredView(scrollView);
478 NSWindow *window = [view window]; 477 NSWindow *window = [view window];
479 NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell]; 478 NSButtonCell *previousDefaultButtonCell = [window defaultButtonCell];
480 479
481 if (states & DefaultState) { 480 if (states & DefaultState) {
482 [window setDefaultButtonCell:buttonCell]; 481 [window setDefaultButtonCell:buttonCell];
483 wkAdvanceDefaultButtonPulseAnimation(buttonCell); 482 wkAdvanceDefaultButtonPulseAnimation(buttonCell);
484 } else if ([previousDefaultButtonCell isEqual:buttonCell]) 483 } else if ([previousDefaultButtonCell isEqual:buttonCell])
485 [window setDefaultButtonCell:nil]; 484 [window setDefaultButtonCell:nil];
486 485
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 break; 743 break;
745 case InnerSpinButtonPart: 744 case InnerSpinButtonPart:
746 paintStepper(states, context, zoomedRect, zoomFactor, scrollView); 745 paintStepper(states, context, zoomedRect, zoomFactor, scrollView);
747 break; 746 break;
748 default: 747 default:
749 break; 748 break;
750 } 749 }
751 } 750 }
752 751
753 } 752 }
OLDNEW
« no previous file with comments | « LayoutTests/platform/chromium/TestExpectations ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698