285// ComboBox
286
287static const IntSize* comboBoxSizes()
288{
289 static const IntSize sizes[3] = { IntSize(19, 21), IntSize(17, 18), IntSize(15, 15) };
290 return sizes;
291}
292// to right bottom left
293static const int* comboBoxMargins(NSControlSize controlSize)
294{
295 static const int margins[3][4] =
296 {
297 { 1, 2, 1, 2 },
298 { 1, 2, 1, 2 },
299 { 1, 0, 1, 0 },
300 };
301 return margins[controlSize];
302}
303
304static NSComboBoxCell *comboBox(ControlStates states, const IntRect& zoomedRect, float zoomFactor)
305{
306 static NSComboBoxCell *comboBoxCell;
307 if (!comboBoxCell) {
308 comboBoxCell = [[NSComboBoxCell alloc] init];
309 [comboBoxCell setButtonBordered:YES];
310 [comboBoxCell setTitle:@""];
311 }
312
313 // Set the control size based off the rectangle we're painting into.
314 setControlSize(comboBoxCell, comboBoxSizes(), zoomedRect.size(), zoomFactor);
315
316 // Update the various states we respond to.
317 updateStates(comboBoxCell, states);
318
319 return comboBoxCell;
320}
321
322static void paintComboBox(ControlStates states, GraphicsContext* context, const IntRect& zoomedRect, float zoomFactor, ScrollView* scrollView)
323{
324 BEGIN_BLOCK_OBJC_EXCEPTIONS
325
326 // Determine the width and height needed for the control and prepare the cell for painting.
327 NSComboBoxCell *comboBoxCell = comboBox(states, zoomedRect, zoomFactor);
328 LocalCurrentGraphicsContext localContext(context);
329
330 GraphicsContextStateSaver stateSaver(*context);
331
332 NSControlSize controlSize = [comboBoxCell controlSize];
333 IntSize zoomedSize = comboBoxSizes()[controlSize];
334 zoomedSize.setWidth(zoomedRect.width()); // Buttons don't ever constrain width, so the zoomed width can just be honored.
335 zoomedSize.setHeight(zoomedSize.height() * zoomFactor);
336 IntRect inflatedRect = inflateRect(zoomedRect, zoomedSize, comboBoxMargins(controlSize), zoomFactor);
337
338 if (zoomFactor != 1.0f) {
339 inflatedRect.setWidth(inflatedRect.width() / zoomFactor);
340 inflatedRect.setHeight(inflatedRect.height() / zoomFactor);
341 context->translate(inflatedRect.x(), inflatedRect.y());
342 context->scale(FloatSize(zoomFactor, zoomFactor));
343 context->translate(-inflatedRect.x(), -inflatedRect.y());
344 }
345
346 [comboBoxCell drawWithFrame:NSRect(inflatedRect) inView:ThemeMac::ensuredView(scrollView)];
347 [comboBoxCell setControlView:nil];
348
349 END_BLOCK_OBJC_EXCEPTIONS
350}
351