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

Side by Side Diff: Source/core/html/HTMLElement.cpp

Issue 16959002: Spatial navigation enhancements (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Applied changes suggested by code reviewer. Created 7 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 20 matching lines...) Expand all
31 #include "XMLNames.h" 31 #include "XMLNames.h"
32 #include "bindings/v8/ScriptController.h" 32 #include "bindings/v8/ScriptController.h"
33 #include "bindings/v8/ScriptEventListener.h" 33 #include "bindings/v8/ScriptEventListener.h"
34 #include "core/css/CSSParser.h" 34 #include "core/css/CSSParser.h"
35 #include "core/css/CSSValuePool.h" 35 #include "core/css/CSSValuePool.h"
36 #include "core/css/StylePropertySet.h" 36 #include "core/css/StylePropertySet.h"
37 #include "core/dom/DocumentFragment.h" 37 #include "core/dom/DocumentFragment.h"
38 #include "core/dom/EventListener.h" 38 #include "core/dom/EventListener.h"
39 #include "core/dom/EventNames.h" 39 #include "core/dom/EventNames.h"
40 #include "core/dom/ExceptionCode.h" 40 #include "core/dom/ExceptionCode.h"
41 #include "core/dom/KeyboardEvent.h"
41 #include "core/dom/NodeTraversal.h" 42 #include "core/dom/NodeTraversal.h"
42 #include "core/dom/Text.h" 43 #include "core/dom/Text.h"
43 #include "core/editing/markup.h" 44 #include "core/editing/markup.h"
44 #include "core/html/HTMLBRElement.h" 45 #include "core/html/HTMLBRElement.h"
45 #include "core/html/HTMLFormElement.h" 46 #include "core/html/HTMLFormElement.h"
46 #include "core/html/HTMLTemplateElement.h" 47 #include "core/html/HTMLTemplateElement.h"
47 #include "core/html/HTMLTextFormControlElement.h" 48 #include "core/html/HTMLTextFormControlElement.h"
48 #include "core/html/parser/HTMLParserIdioms.h" 49 #include "core/html/parser/HTMLParserIdioms.h"
49 #include "core/loader/FrameLoader.h" 50 #include "core/loader/FrameLoader.h"
50 #include "core/page/Frame.h" 51 #include "core/page/Frame.h"
52 #include "core/page/Settings.h"
51 #include "core/rendering/RenderWordBreak.h" 53 #include "core/rendering/RenderWordBreak.h"
52 #include <wtf/StdLibExtras.h> 54 #include <wtf/StdLibExtras.h>
53 #include <wtf/text/CString.h> 55 #include <wtf/text/CString.h>
54 56
55 namespace WebCore { 57 namespace WebCore {
56 58
57 using namespace HTMLNames; 59 using namespace HTMLNames;
58 using namespace WTF; 60 using namespace WTF;
59 61
60 using std::min; 62 using std::min;
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 593
592 if (verticalAlignValue != CSSValueInvalid) 594 if (verticalAlignValue != CSSValueInvalid)
593 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, verticalAlignValue); 595 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, verticalAlignValue);
594 } 596 }
595 597
596 bool HTMLElement::hasCustomFocusLogic() const 598 bool HTMLElement::hasCustomFocusLogic() const
597 { 599 {
598 return false; 600 return false;
599 } 601 }
600 602
603 bool HTMLElement::supportsSpatialNavigationFocus() const
604 {
605 EventTarget* target = const_cast<HTMLElement*>(this);
606 return target->hasEventListeners(eventNames().clickEvent)
tkent 2013/06/16 22:50:24 This looks an incompatible change. An element with
607 || target->hasEventListeners(eventNames().keydownEvent)
608 || target->hasEventListeners(eventNames().keypressEvent)
609 || target->hasEventListeners(eventNames().keyupEvent);
610 }
611
601 bool HTMLElement::supportsFocus() const 612 bool HTMLElement::supportsFocus() const
602 { 613 {
603 return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable()); 614 return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable())
615 || supportsSpatialNavigationFocus();
604 } 616 }
605 617
606 String HTMLElement::contentEditable() const 618 String HTMLElement::contentEditable() const
607 { 619 {
608 const AtomicString& value = fastGetAttribute(contenteditableAttr); 620 const AtomicString& value = fastGetAttribute(contenteditableAttr);
609 621
610 if (value.isNull()) 622 if (value.isNull())
611 return "inherit"; 623 return "inherit";
612 if (value.isEmpty() || equalIgnoringCase(value, "true")) 624 if (value.isEmpty() || equalIgnoringCase(value, "true"))
613 return "true"; 625 return "true";
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 return; 1029 return;
1018 1030
1019 // If the string is a named CSS color or a 3/6-digit hex color, use that. 1031 // If the string is a named CSS color or a 3/6-digit hex color, use that.
1020 Color parsedColor(colorString); 1032 Color parsedColor(colorString);
1021 if (!parsedColor.isValid()) 1033 if (!parsedColor.isValid())
1022 parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString)); 1034 parsedColor.setRGB(parseColorStringWithCrazyLegacyRules(colorString));
1023 1035
1024 style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.r gb())); 1036 style->setProperty(propertyID, cssValuePool().createColorValue(parsedColor.r gb()));
1025 } 1037 }
1026 1038
1039 void HTMLElement::defaultEventHandler(Event* event)
1040 {
1041 if (event->type() == eventNames().keypressEvent && event->isKeyboardEvent()) {
1042 handleKeypressEvent(toKeyboardEvent(event));
1043 if (event->defaultHandled())
1044 return;
1045 }
1046
1047 StyledElement::defaultEventHandler(event);
1048 }
1049
1050 void HTMLElement::handleKeypressEvent(KeyboardEvent* event)
1051 {
1052 if (!document()->settings()->spatialNavigationEnabled() || !supportsFocus())
1053 return;
1054 int charCode = event->charCode();
1055 if (charCode == '\r' || charCode == ' ') {
1056 dispatchSimulatedClick(event);
1057 event->setDefaultHandled();
1058 }
1059 }
1060
1027 } // namespace WebCore 1061 } // namespace WebCore
1028 1062
1029 #ifndef NDEBUG 1063 #ifndef NDEBUG
1030 1064
1031 // For use in the debugger 1065 // For use in the debugger
1032 void dumpInnerHTML(WebCore::HTMLElement*); 1066 void dumpInnerHTML(WebCore::HTMLElement*);
1033 1067
1034 void dumpInnerHTML(WebCore::HTMLElement* element) 1068 void dumpInnerHTML(WebCore::HTMLElement* element)
1035 { 1069 {
1036 printf("%s\n", element->innerHTML().ascii().data()); 1070 printf("%s\n", element->innerHTML().ascii().data());
1037 } 1071 }
1038 #endif 1072 #endif
OLDNEW
« Source/core/dom/KeyboardEvent.h ('K') | « Source/core/html/HTMLElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698