| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google 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 15 matching lines...) Expand all Loading... |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) | 27 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
| 28 #include "DateTimeEditElement.h" | 28 #include "DateTimeEditElement.h" |
| 29 | 29 |
| 30 #include "DateComponents.h" | 30 #include "DateComponents.h" |
| 31 #include "DateTimeFieldElements.h" | 31 #include "DateTimeFieldElements.h" |
| 32 #include "DateTimeFieldsState.h" | 32 #include "DateTimeFieldsState.h" |
| 33 #include "DateTimeFormat.h" | 33 #include "DateTimeFormat.h" |
| 34 #include "DateTimeSymbolicFieldElement.h" | 34 #include "DateTimeSymbolicFieldElement.h" |
| 35 #include "EventHandler.h" | 35 #include "EventHandler.h" |
| 36 #include "FontCache.h" |
| 36 #include "HTMLNames.h" | 37 #include "HTMLNames.h" |
| 37 #include "KeyboardEvent.h" | 38 #include "KeyboardEvent.h" |
| 38 #include "MouseEvent.h" | 39 #include "MouseEvent.h" |
| 39 #include "PlatformLocale.h" | 40 #include "PlatformLocale.h" |
| 41 #include "RenderStyle.h" |
| 42 #include "StyleResolver.h" |
| 40 #include "Text.h" | 43 #include "Text.h" |
| 41 #include <wtf/DateMath.h> | 44 #include <wtf/DateMath.h> |
| 42 #include <wtf/text/StringBuilder.h> | 45 #include <wtf/text/StringBuilder.h> |
| 43 | 46 |
| 44 namespace WebCore { | 47 namespace WebCore { |
| 45 | 48 |
| 46 using namespace HTMLNames; | 49 using namespace HTMLNames; |
| 47 | 50 |
| 48 class DateTimeEditBuilder : private DateTimeFormat::TokenHandler { | 51 class DateTimeEditBuilder : private DateTimeFormat::TokenHandler { |
| 49 WTF_MAKE_NONCOPYABLE(DateTimeEditBuilder); | 52 WTF_MAKE_NONCOPYABLE(DateTimeEditBuilder); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DateTimeEditElement::EditControlOwner::~EditControlOwner() | 297 DateTimeEditElement::EditControlOwner::~EditControlOwner() |
| 295 { | 298 { |
| 296 } | 299 } |
| 297 | 300 |
| 298 DateTimeEditElement::DateTimeEditElement(Document* document, EditControlOwner& e
ditControlOwner) | 301 DateTimeEditElement::DateTimeEditElement(Document* document, EditControlOwner& e
ditControlOwner) |
| 299 : HTMLDivElement(divTag, document) | 302 : HTMLDivElement(divTag, document) |
| 300 , m_editControlOwner(&editControlOwner) | 303 , m_editControlOwner(&editControlOwner) |
| 301 { | 304 { |
| 302 DEFINE_STATIC_LOCAL(AtomicString, dateTimeEditPseudoId, ("-webkit-datetime-e
dit")); | 305 DEFINE_STATIC_LOCAL(AtomicString, dateTimeEditPseudoId, ("-webkit-datetime-e
dit")); |
| 303 setShadowPseudoId(dateTimeEditPseudoId); | 306 setShadowPseudoId(dateTimeEditPseudoId); |
| 307 setHasCustomCallbacks(); |
| 304 } | 308 } |
| 305 | 309 |
| 306 DateTimeEditElement::~DateTimeEditElement() | 310 DateTimeEditElement::~DateTimeEditElement() |
| 307 { | 311 { |
| 308 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 312 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) |
| 309 m_fields[fieldIndex]->removeEventHandler(); | 313 m_fields[fieldIndex]->removeEventHandler(); |
| 310 } | 314 } |
| 311 | 315 |
| 312 void DateTimeEditElement::addField(PassRefPtr<DateTimeFieldElement> field) | 316 void DateTimeEditElement::addField(PassRefPtr<DateTimeFieldElement> field) |
| 313 { | 317 { |
| 314 if (m_fields.size() == m_fields.capacity()) | 318 if (m_fields.size() == m_fields.capacity()) |
| 315 return; | 319 return; |
| 316 m_fields.append(field.get()); | 320 m_fields.append(field.get()); |
| 317 appendChild(field); | 321 appendChild(field); |
| 318 } | 322 } |
| 319 | 323 |
| 320 void DateTimeEditElement::blurByOwner() | 324 void DateTimeEditElement::blurByOwner() |
| 321 { | 325 { |
| 322 if (DateTimeFieldElement* field = focusedField()) | 326 if (DateTimeFieldElement* field = focusedField()) |
| 323 field->blur(); | 327 field->blur(); |
| 324 } | 328 } |
| 325 | 329 |
| 326 PassRefPtr<DateTimeEditElement> DateTimeEditElement::create(Document* document,
EditControlOwner& editControlOwner) | 330 PassRefPtr<DateTimeEditElement> DateTimeEditElement::create(Document* document,
EditControlOwner& editControlOwner) |
| 327 { | 331 { |
| 328 RefPtr<DateTimeEditElement> container = adoptRef(new DateTimeEditElement(doc
ument, editControlOwner)); | 332 RefPtr<DateTimeEditElement> container = adoptRef(new DateTimeEditElement(doc
ument, editControlOwner)); |
| 329 return container.release(); | 333 return container.release(); |
| 330 } | 334 } |
| 331 | 335 |
| 336 PassRefPtr<RenderStyle> DateTimeEditElement::customStyleForRenderer() |
| 337 { |
| 338 // FIXME: This is a kind of layout. We might want to introduce new renderer. |
| 339 FontCachePurgePreventer fontCachePurgePreventer; |
| 340 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle
ment(this); |
| 341 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get()); |
| 342 float width = 0; |
| 343 for (Node* child = firstChild(); child; child = child->nextSibling()) { |
| 344 if (!child->isElementNode()) |
| 345 continue; |
| 346 Element* childElement = toElement(child); |
| 347 if (childElement->isDateTimeFieldElement()) { |
| 348 // We need to pass the Font of this element because child elements |
| 349 // can't resolve inherited style at this timing. |
| 350 width += static_cast<DateTimeFieldElement*>(childElement)->maximumWi
dth(style->font()); |
| 351 } else { |
| 352 // ::-webkit-datetime-edit-text case. It has no |
| 353 // border/padding/margin in html.css. |
| 354 width += style->font().width(childElement->textContent()); |
| 355 } |
| 356 } |
| 357 style->setMinWidth(Length(ceilf(width), Fixed)); |
| 358 return style.release(); |
| 359 } |
| 360 |
| 332 void DateTimeEditElement::didBlurFromField() | 361 void DateTimeEditElement::didBlurFromField() |
| 333 { | 362 { |
| 334 if (m_editControlOwner) | 363 if (m_editControlOwner) |
| 335 m_editControlOwner->didBlurFromControl(); | 364 m_editControlOwner->didBlurFromControl(); |
| 336 } | 365 } |
| 337 | 366 |
| 338 void DateTimeEditElement::didFocusOnField() | 367 void DateTimeEditElement::didFocusOnField() |
| 339 { | 368 { |
| 340 if (m_editControlOwner) | 369 if (m_editControlOwner) |
| 341 m_editControlOwner->didFocusOnControl(); | 370 m_editControlOwner->didFocusOnControl(); |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 { | 589 { |
| 561 DateTimeFieldsState dateTimeFieldsState; | 590 DateTimeFieldsState dateTimeFieldsState; |
| 562 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) | 591 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) |
| 563 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState); | 592 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState); |
| 564 return dateTimeFieldsState; | 593 return dateTimeFieldsState; |
| 565 } | 594 } |
| 566 | 595 |
| 567 } // namespace WebCore | 596 } // namespace WebCore |
| 568 | 597 |
| 569 #endif | 598 #endif |
| OLD | NEW |