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

Side by Side Diff: Source/core/editing/EditingStyle.cpp

Issue 183763033: Avoid calling hasAttribute() and then getAttribute() for performance (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/core/editing/SplitElementCommand.cpp » ('j') | 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) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 283
284 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const 284 void HTMLAttributeEquivalent::addToStyle(Element* element, EditingStyle* style) const
285 { 285 {
286 if (RefPtrWillBeRawPtr<CSSValue> value = attributeValueAsCSSValue(element)) 286 if (RefPtrWillBeRawPtr<CSSValue> value = attributeValueAsCSSValue(element))
287 style->setProperty(m_propertyID, value->cssText()); 287 style->setProperty(m_propertyID, value->cssText());
288 } 288 }
289 289
290 PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSVal ue(Element* element) const 290 PassRefPtrWillBeRawPtr<CSSValue> HTMLAttributeEquivalent::attributeValueAsCSSVal ue(Element* element) const
291 { 291 {
292 ASSERT(element); 292 ASSERT(element);
293 if (!element->hasAttribute(m_attrName)) 293 const AtomicString& value = element->getAttribute(m_attrName);
294 if (value.isNull())
294 return nullptr; 295 return nullptr;
295 296
296 RefPtr<MutableStylePropertySet> dummyStyle; 297 RefPtr<MutableStylePropertySet> dummyStyle;
297 dummyStyle = MutableStylePropertySet::create(); 298 dummyStyle = MutableStylePropertySet::create();
298 dummyStyle->setProperty(m_propertyID, element->getAttribute(m_attrName)); 299 dummyStyle->setProperty(m_propertyID, value);
299 return dummyStyle->getPropertyCSSValue(m_propertyID); 300 return dummyStyle->getPropertyCSSValue(m_propertyID);
300 } 301 }
301 302
302 class HTMLFontSizeEquivalent FINAL : public HTMLAttributeEquivalent { 303 class HTMLFontSizeEquivalent FINAL : public HTMLAttributeEquivalent {
303 public: 304 public:
304 static PassOwnPtr<HTMLFontSizeEquivalent> create() 305 static PassOwnPtr<HTMLFontSizeEquivalent> create()
305 { 306 {
306 return adoptPtr(new HTMLFontSizeEquivalent()); 307 return adoptPtr(new HTMLFontSizeEquivalent());
307 } 308 }
308 virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(Element*) const OVERRIDE; 309 virtual PassRefPtrWillBeRawPtr<CSSValue> attributeValueAsCSSValue(Element*) const OVERRIDE;
309 310
310 private: 311 private:
311 HTMLFontSizeEquivalent(); 312 HTMLFontSizeEquivalent();
312 }; 313 };
313 314
314 HTMLFontSizeEquivalent::HTMLFontSizeEquivalent() 315 HTMLFontSizeEquivalent::HTMLFontSizeEquivalent()
315 : HTMLAttributeEquivalent(CSSPropertyFontSize, HTMLNames::fontTag, HTMLNames ::sizeAttr) 316 : HTMLAttributeEquivalent(CSSPropertyFontSize, HTMLNames::fontTag, HTMLNames ::sizeAttr)
316 { 317 {
317 } 318 }
318 319
319 PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValu e(Element* element) const 320 PassRefPtrWillBeRawPtr<CSSValue> HTMLFontSizeEquivalent::attributeValueAsCSSValu e(Element* element) const
320 { 321 {
321 ASSERT(element); 322 ASSERT(element);
322 if (!element->hasAttribute(m_attrName)) 323 const AtomicString& value = element->getAttribute(m_attrName);
324 if (value.isNull())
323 return nullptr; 325 return nullptr;
324 CSSValueID size; 326 CSSValueID size;
325 if (!HTMLFontElement::cssValueFromFontSizeNumber(element->getAttribute(m_att rName), size)) 327 if (!HTMLFontElement::cssValueFromFontSizeNumber(value, size))
326 return nullptr; 328 return nullptr;
327 return CSSPrimitiveValue::createIdentifier(size); 329 return CSSPrimitiveValue::createIdentifier(size);
328 } 330 }
329 331
330 float EditingStyle::NoFontDelta = 0.0f; 332 float EditingStyle::NoFontDelta = 0.0f;
331 333
332 EditingStyle::EditingStyle() 334 EditingStyle::EditingStyle()
333 : m_shouldUseFixedDefaultFontSize(false) 335 : m_shouldUseFixedDefaultFontSize(false)
334 , m_fontSizeDelta(NoFontDelta) 336 , m_fontSizeDelta(NoFontDelta)
335 { 337 {
(...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 { 1634 {
1633 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 1635 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
1634 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor); 1636 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = CSSComputedStyleDecl aration::create(ancestor);
1635 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1637 if (!hasTransparentBackgroundColor(ancestorStyle.get()))
1636 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor ); 1638 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor );
1637 } 1639 }
1638 return nullptr; 1640 return nullptr;
1639 } 1641 }
1640 1642
1641 } 1643 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/SplitElementCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698