1 /** 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2003 Apple Computer, Inc. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Library General Public 9 * License as published by the Free Software Foundation; either 10 * version 2 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Library General Public License for more details. 16 * 17 * You should have received a copy of the GNU Library General Public License 18 * along with this library; see the file COPYING.LIB. If not, write to 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 20 * Boston, MA 02110-1301, USA. 21 */ 22 23 #include "config.h" 24 #include "HTMLMetaElement.h" 25 26 #include "Document.h" 27 #include "HTMLNames.h" 28 #include "MappedAttribute.h" 29 30 #ifdef ANDROID_META_SUPPORT 31 #include "Settings.h" 32 #include "WebViewCore.h" 33 #endif 34 35 namespace WebCore { 36 37 using namespace HTMLNames; 38 HTMLMetaElement(const QualifiedName & tagName,Document * doc)39 HTMLMetaElement::HTMLMetaElement(const QualifiedName& tagName, Document* doc) 40 : HTMLElement(tagName, doc) 41 { 42 ASSERT(hasTagName(metaTag)); 43 } 44 ~HTMLMetaElement()45 HTMLMetaElement::~HTMLMetaElement() 46 { 47 } 48 parseMappedAttribute(MappedAttribute * attr)49 void HTMLMetaElement::parseMappedAttribute(MappedAttribute* attr) 50 { 51 if (attr->name() == http_equivAttr) { 52 m_equiv = attr->value(); 53 process(); 54 } else if (attr->name() == contentAttr) { 55 m_content = attr->value(); 56 process(); 57 } else if (attr->name() == nameAttr) { 58 // Do nothing. 59 } else 60 HTMLElement::parseMappedAttribute(attr); 61 } 62 insertedIntoDocument()63 void HTMLMetaElement::insertedIntoDocument() 64 { 65 HTMLElement::insertedIntoDocument(); 66 process(); 67 } 68 process()69 void HTMLMetaElement::process() 70 { 71 #ifdef ANDROID_META_SUPPORT 72 if (!inDocument() || m_content.isNull()) 73 return; 74 bool updateViewport = false; 75 if (equalIgnoringCase(name(), "viewport")) { 76 document()->processMetadataSettings(m_content); 77 updateViewport = true; 78 } else if (equalIgnoringCase(name(), "format-detection")) 79 document()->processMetadataSettings(m_content); 80 else if ((equalIgnoringCase(name(), "HandheldFriendly") 81 && equalIgnoringCase(m_content, "true") || 82 equalIgnoringCase(name(), "MobileOptimized")) 83 && document()->settings()->viewportWidth() == -1) { 84 // fit mobile sites directly in the screen 85 document()->settings()->setMetadataSettings("width", "device-width"); 86 updateViewport = true; 87 } 88 // update the meta data if it is the top document 89 if (updateViewport && !document()->ownerElement()) { 90 FrameView* view = document()->view(); 91 if (view) 92 android::WebViewCore::getWebViewCore(view)->updateViewport(); 93 } 94 #endif 95 // Get the document to process the tag, but only if we're actually part of DOM tree (changing a meta tag while 96 // it's not in the tree shouldn't have any effect on the document) 97 if (inDocument() && !m_equiv.isNull() && !m_content.isNull()) 98 document()->processHttpEquiv(m_equiv, m_content); 99 } 100 content() const101 String HTMLMetaElement::content() const 102 { 103 return getAttribute(contentAttr); 104 } 105 setContent(const String & value)106 void HTMLMetaElement::setContent(const String& value) 107 { 108 setAttribute(contentAttr, value); 109 } 110 httpEquiv() const111 String HTMLMetaElement::httpEquiv() const 112 { 113 return getAttribute(http_equivAttr); 114 } 115 setHttpEquiv(const String & value)116 void HTMLMetaElement::setHttpEquiv(const String& value) 117 { 118 setAttribute(http_equivAttr, value); 119 } 120 name() const121 String HTMLMetaElement::name() const 122 { 123 return getAttribute(nameAttr); 124 } 125 setName(const String & value)126 void HTMLMetaElement::setName(const String& value) 127 { 128 setAttribute(nameAttr, value); 129 } 130 scheme() const131 String HTMLMetaElement::scheme() const 132 { 133 return getAttribute(schemeAttr); 134 } 135 setScheme(const String & value)136 void HTMLMetaElement::setScheme(const String &value) 137 { 138 setAttribute(schemeAttr, value); 139 } 140 141 } 142