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

Side by Side Diff: Source/WebCore/html/shadow/DateTimeEditElement.cpp

Issue 12159003: Merge 141195 (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1364/
Patch Set: Created 7 years, 10 months 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 | « Source/WebCore/html/shadow/DateTimeEditElement.h ('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) 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 DEFINE_STATIC_LOCAL(AtomicString, textPseudoId, ("-webkit-datetime-edit-text ", AtomicString::ConstructFromLiteral)); 296 DEFINE_STATIC_LOCAL(AtomicString, textPseudoId, ("-webkit-datetime-edit-text ", AtomicString::ConstructFromLiteral));
297 ASSERT(text.length()); 297 ASSERT(text.length());
298 RefPtr<HTMLDivElement> element = HTMLDivElement::create(m_editElement.docume nt()); 298 RefPtr<HTMLDivElement> element = HTMLDivElement::create(m_editElement.docume nt());
299 element->setPseudo(textPseudoId); 299 element->setPseudo(textPseudoId);
300 if (m_parameters.locale.isRTL() && text.length()) { 300 if (m_parameters.locale.isRTL() && text.length()) {
301 Direction dir = direction(text[0]); 301 Direction dir = direction(text[0]);
302 if (dir == SegmentSeparator || dir == WhiteSpaceNeutral || dir == OtherN eutral) 302 if (dir == SegmentSeparator || dir == WhiteSpaceNeutral || dir == OtherN eutral)
303 element->appendChild(Text::create(m_editElement.document(), String(& rightToLeftMark, 1))); 303 element->appendChild(Text::create(m_editElement.document(), String(& rightToLeftMark, 1)));
304 } 304 }
305 element->appendChild(Text::create(m_editElement.document(), text)); 305 element->appendChild(Text::create(m_editElement.document(), text));
306 m_editElement.appendChild(element); 306 m_editElement.fieldsWrapperElement()->appendChild(element);
307 } 307 }
308 308
309 DateTimeNumericFieldElement::Parameters DateTimeEditBuilder::createNumericFieldP arameters(const Decimal& msPerFieldUnit, const Decimal& msPerFieldSize) const 309 DateTimeNumericFieldElement::Parameters DateTimeEditBuilder::createNumericFieldP arameters(const Decimal& msPerFieldUnit, const Decimal& msPerFieldSize) const
310 { 310 {
311 ASSERT(!msPerFieldUnit.isZero()); 311 ASSERT(!msPerFieldUnit.isZero());
312 ASSERT(!msPerFieldSize.isZero()); 312 ASSERT(!msPerFieldSize.isZero());
313 Decimal stepMilliseconds = stepRange().step(); 313 Decimal stepMilliseconds = stepRange().step();
314 ASSERT(!stepMilliseconds.isZero()); 314 ASSERT(!stepMilliseconds.isZero());
315 315
316 DateTimeNumericFieldElement::Parameters parameters(1, 0); 316 DateTimeNumericFieldElement::Parameters parameters(1, 0);
(...skipping 22 matching lines...) Expand all
339 setPseudo(dateTimeEditPseudoId); 339 setPseudo(dateTimeEditPseudoId);
340 setHasCustomCallbacks(); 340 setHasCustomCallbacks();
341 } 341 }
342 342
343 DateTimeEditElement::~DateTimeEditElement() 343 DateTimeEditElement::~DateTimeEditElement()
344 { 344 {
345 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) 345 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex)
346 m_fields[fieldIndex]->removeEventHandler(); 346 m_fields[fieldIndex]->removeEventHandler();
347 } 347 }
348 348
349 inline Element* DateTimeEditElement::fieldsWrapperElement() const
350 {
351 ASSERT(firstChild());
352 return toElement(firstChild());
353 }
354
349 void DateTimeEditElement::addField(PassRefPtr<DateTimeFieldElement> field) 355 void DateTimeEditElement::addField(PassRefPtr<DateTimeFieldElement> field)
350 { 356 {
351 if (m_fields.size() == m_fields.capacity()) 357 if (m_fields.size() == m_fields.capacity())
352 return; 358 return;
353 m_fields.append(field.get()); 359 m_fields.append(field.get());
354 appendChild(field); 360 fieldsWrapperElement()->appendChild(field);
355 } 361 }
356 362
357 bool DateTimeEditElement::anyEditableFieldsHaveValues() const 363 bool DateTimeEditElement::anyEditableFieldsHaveValues() const
358 { 364 {
359 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) { 365 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) {
360 if (!m_fields[fieldIndex]->isReadOnly() && m_fields[fieldIndex]->hasValu e()) 366 if (!m_fields[fieldIndex]->isReadOnly() && m_fields[fieldIndex]->hasValu e())
361 return true; 367 return true;
362 } 368 }
363 return false; 369 return false;
364 } 370 }
(...skipping 10 matching lines...) Expand all
375 return container.release(); 381 return container.release();
376 } 382 }
377 383
378 PassRefPtr<RenderStyle> DateTimeEditElement::customStyleForRenderer() 384 PassRefPtr<RenderStyle> DateTimeEditElement::customStyleForRenderer()
379 { 385 {
380 // FIXME: This is a kind of layout. We might want to introduce new renderer. 386 // FIXME: This is a kind of layout. We might want to introduce new renderer.
381 FontCachePurgePreventer fontCachePurgePreventer; 387 FontCachePurgePreventer fontCachePurgePreventer;
382 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this); 388 RefPtr<RenderStyle> originalStyle = document()->styleResolver()->styleForEle ment(this);
383 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get()); 389 RefPtr<RenderStyle> style = RenderStyle::clone(originalStyle.get());
384 float width = 0; 390 float width = 0;
385 for (Node* child = firstChild(); child; child = child->nextSibling()) { 391 for (Node* child = fieldsWrapperElement()->firstChild(); child; child = chil d->nextSibling()) {
386 if (!child->isElementNode()) 392 if (!child->isElementNode())
387 continue; 393 continue;
388 Element* childElement = toElement(child); 394 Element* childElement = toElement(child);
389 if (childElement->isDateTimeFieldElement()) { 395 if (childElement->isDateTimeFieldElement()) {
390 // We need to pass the Font of this element because child elements 396 // We need to pass the Font of this element because child elements
391 // can't resolve inherited style at this timing. 397 // can't resolve inherited style at this timing.
392 width += static_cast<DateTimeFieldElement*>(childElement)->maximumWi dth(style->font()); 398 width += static_cast<DateTimeFieldElement*>(childElement)->maximumWi dth(style->font());
393 } else { 399 } else {
394 // ::-webkit-datetime-edit-text case. It has no 400 // ::-webkit-datetime-edit-text case. It has no
395 // border/padding/margin in html.css. 401 // border/padding/margin in html.css.
396 width += style->font().width(childElement->textContent()); 402 width += style->font().width(childElement->textContent());
397 } 403 }
398 } 404 }
399 style->setMinWidth(Length(ceilf(width), Fixed)); 405 style->setWidth(Length(ceilf(width), Fixed));
400 return style.release(); 406 return style.release();
401 } 407 }
402 408
403 void DateTimeEditElement::didBlurFromField() 409 void DateTimeEditElement::didBlurFromField()
404 { 410 {
405 if (m_editControlOwner) 411 if (m_editControlOwner)
406 m_editControlOwner->didBlurFromControl(); 412 m_editControlOwner->didBlurFromControl();
407 } 413 }
408 414
409 void DateTimeEditElement::didFocusOnField() 415 void DateTimeEditElement::didFocusOnField()
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 return isDisabled() || isReadOnly(); 513 return isDisabled() || isReadOnly();
508 } 514 }
509 515
510 bool DateTimeEditElement::isReadOnly() const 516 bool DateTimeEditElement::isReadOnly() const
511 { 517 {
512 return m_editControlOwner && m_editControlOwner->isEditControlOwnerReadOnly( ); 518 return m_editControlOwner && m_editControlOwner->isEditControlOwnerReadOnly( );
513 } 519 }
514 520
515 void DateTimeEditElement::layout(const LayoutParameters& layoutParameters, const DateComponents& dateValue) 521 void DateTimeEditElement::layout(const LayoutParameters& layoutParameters, const DateComponents& dateValue)
516 { 522 {
523 DEFINE_STATIC_LOCAL(AtomicString, fieldsWrapperPseudoId, ("-webkit-datetime- edit-fields-wrapper", AtomicString::ConstructFromLiteral));
524 if (!firstChild()) {
525 RefPtr<HTMLDivElement> element = HTMLDivElement::create(document());
526 element->setPseudo(fieldsWrapperPseudoId);
527 appendChild(element.get());
528 }
529 Element* fieldsWrapper = fieldsWrapperElement();
530
517 size_t focusedFieldIndex = this->focusedFieldIndex(); 531 size_t focusedFieldIndex = this->focusedFieldIndex();
518 DateTimeFieldElement* const focusedField = fieldAt(focusedFieldIndex); 532 DateTimeFieldElement* const focusedField = fieldAt(focusedFieldIndex);
519 const AtomicString focusedFieldId = focusedField ? focusedField->shadowPseud oId() : nullAtom; 533 const AtomicString focusedFieldId = focusedField ? focusedField->shadowPseud oId() : nullAtom;
520 534
521 DateTimeEditBuilder builder(*this, layoutParameters, dateValue); 535 DateTimeEditBuilder builder(*this, layoutParameters, dateValue);
522 Node* lastChildToBeRemoved = lastChild(); 536 Node* lastChildToBeRemoved = fieldsWrapper->lastChild();
523 if (!builder.build(layoutParameters.dateTimeFormat) || m_fields.isEmpty()) { 537 if (!builder.build(layoutParameters.dateTimeFormat) || m_fields.isEmpty()) {
524 lastChildToBeRemoved = lastChild(); 538 lastChildToBeRemoved = fieldsWrapper->lastChild();
525 builder.build(layoutParameters.fallbackDateTimeFormat); 539 builder.build(layoutParameters.fallbackDateTimeFormat);
526 } 540 }
527 541
528 if (focusedFieldIndex != invalidFieldIndex) { 542 if (focusedFieldIndex != invalidFieldIndex) {
529 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) { 543 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) {
530 if (m_fields[fieldIndex]->shadowPseudoId() == focusedFieldId) { 544 if (m_fields[fieldIndex]->shadowPseudoId() == focusedFieldId) {
531 focusedFieldIndex = fieldIndex; 545 focusedFieldIndex = fieldIndex;
532 break; 546 break;
533 } 547 }
534 } 548 }
535 if (DateTimeFieldElement* field = fieldAt(std::min(focusedFieldIndex, m_ fields.size() - 1))) 549 if (DateTimeFieldElement* field = fieldAt(std::min(focusedFieldIndex, m_ fields.size() - 1)))
536 field->focus(); 550 field->focus();
537 } 551 }
538 552
539 if (lastChildToBeRemoved) { 553 if (lastChildToBeRemoved) {
540 for (Node* childNode = firstChild(); childNode; childNode = firstChild() ) { 554 for (Node* childNode = fieldsWrapper->firstChild(); childNode; childNode = fieldsWrapper->firstChild()) {
541 removeChild(childNode); 555 fieldsWrapper->removeChild(childNode);
542 if (childNode == lastChildToBeRemoved) 556 if (childNode == lastChildToBeRemoved)
543 break; 557 break;
544 } 558 }
559 setNeedsStyleRecalc();
545 } 560 }
546 } 561 }
547 562
548 AtomicString DateTimeEditElement::localeIdentifier() const 563 AtomicString DateTimeEditElement::localeIdentifier() const
549 { 564 {
550 return m_editControlOwner ? m_editControlOwner->localeIdentifier() : nullAto m; 565 return m_editControlOwner ? m_editControlOwner->localeIdentifier() : nullAto m;
551 } 566 }
552 567
553 void DateTimeEditElement::readOnlyStateChanged() 568 void DateTimeEditElement::readOnlyStateChanged()
554 { 569 {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 { 661 {
647 DateTimeFieldsState dateTimeFieldsState; 662 DateTimeFieldsState dateTimeFieldsState;
648 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex) 663 for (size_t fieldIndex = 0; fieldIndex < m_fields.size(); ++fieldIndex)
649 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState); 664 m_fields[fieldIndex]->populateDateTimeFieldsState(dateTimeFieldsState);
650 return dateTimeFieldsState; 665 return dateTimeFieldsState;
651 } 666 }
652 667
653 } // namespace WebCore 668 } // namespace WebCore
654 669
655 #endif 670 #endif
OLDNEW
« no previous file with comments | « Source/WebCore/html/shadow/DateTimeEditElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698