Summary: | Implement HTML5 draggable | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Erik Arvidsson <arv> | ||||||||||
Component: | DOM | Assignee: | Erik Arvidsson <arv> | ||||||||||
Status: | RESOLVED FIXED | ||||||||||||
Severity: | Normal | CC: | darin | ||||||||||
Priority: | P2 | ||||||||||||
Version: | 528+ (Nightly build) | ||||||||||||
Hardware: | All | ||||||||||||
OS: | All | ||||||||||||
URL: | http://www.whatwg.org/specs/web-apps/current-work/#the-draggable-attribute | ||||||||||||
Bug Depends on: | |||||||||||||
Bug Blocks: | 32934 | ||||||||||||
Attachments: |
|
Description
Erik Arvidsson
2009-06-08 16:17:07 PDT
This is actually trivial. All we need to do is add the following to the ua style sheet. [draggable] { -webkit-user-drag: element; -webkit-user-select: none; } Created attachment 32215 [details]
Patch
Comment on attachment 32215 [details]
Patch
The style part should probably be implemented in parseMappedAttribute instead of the ua stylesheet.
Comment on attachment 32215 [details]
Patch
Hyatt confirms that "draggable" should be implemented in code via parseMappedAttribute rather than in the UA stylesheet, because in our CSS implementation it's fairly inefficient to have an attribute selector that's not scoped to particular tags. I believe HTMLElement::parseMappedAttribute would be the right place.
r- to fix this, patch otherwise looks good to me.
Created attachment 32253 [details]
Uses parseMappedAttribute instead of the user style sheet
I also did some testing with Firefox 3.5 and it ignores the case of true and false so I made all the checks ignore the case. Also, added code to correctly handle when the attribute is set to something other than true or false and updated the test to reflect that.
(In reply to comment #4) > (From update of attachment 32215 [details]) > Hyatt confirms that "draggable" should be implemented in code via > parseMappedAttribute rather than in the UA stylesheet, because in our CSS > implementation it's fairly inefficient to have an attribute selector that's not > scoped to particular tags. I believe HTMLElement::parseMappedAttribute would be > the right place. Thanks for the hint about parseMappedAttribute. It makes total sense to me now. I'll try to keep that in mind any time I think I need to touch the UA stylesheet. Comment on attachment 32253 [details] Uses parseMappedAttribute instead of the user style sheet > + if (equalIgnoringCase(getAttribute(draggableAttr), "true")) > + return true; > + if (equalIgnoringCase(getAttribute(draggableAttr), "false")) > + return false; It would be more efficient to call getAttribute only once. A local variable of type const AtomicString& can be used to hold the attribute value. > +void HTMLElement::setDraggable(MappedAttribute* attr) I think it would be best to give this a different name, rather than using overloading. Perhaps it could be called parseDraggableAttribute. > +void HTMLElement::setDraggable(const bool& value) This should just be bool, not const bool&. > + void setDraggable(MappedAttribute*); This newly-added member function should be private. This looks good, but I'm going to say review- since I'd really like to see the name and visibility of the setDraggable function that takes an attribute changed. (In reply to comment #7) Thanks for the review Darin > (From update of attachment 32253 [details]) > > + if (equalIgnoringCase(getAttribute(draggableAttr), "true")) > > + return true; > > + if (equalIgnoringCase(getAttribute(draggableAttr), "false")) > > + return false; > > It would be more efficient to call getAttribute only once. A local variable of > type const AtomicString& can be used to hold the attribute value. Done. > > +void HTMLElement::setDraggable(MappedAttribute* attr) > > I think it would be best to give this a different name, rather than using > overloading. Perhaps it could be called parseDraggableAttribute. I ended up inlining it in parseMappedAttribute since the logic is pretty simple and other cases are more complicated already. > > +void HTMLElement::setDraggable(const bool& value) > > This should just be bool, not const bool&. Done. > > + void setDraggable(MappedAttribute*); > > This newly-added member function should be private. > > This looks good, but I'm going to say review- since I'd really like to see the > name and visibility of the setDraggable function that takes an attribute > changed. Another patch coming in a sec Created attachment 32266 [details]
Fixed Darin's comments.
Comment on attachment 32266 [details]
Fixed Darin's comments.
Looks to me like the comments are all addressed, and I do not see any new issues. Thanks for the contribution and the several revised versions! r=me
Comment on attachment 32266 [details]
Fixed Darin's comments.
There are style issues in this patch:
Spacing:
+ for (var i = 16; i < 24; i++) {
+ elements[i].draggable = i < 20;
+ }
Extra {
151 } else if (equalIgnoringCase(value, "false")) {
152 addCSSProperty(attr, CSSPropertyWebkitUserDrag, CSSValueNone);
153 }
Extra space:
357 if (equalIgnoringCase(value , "true"))
Those certainly could be corrected when landing. But having them here, makes this hard to land automatically.
(In reply to comment #11) > (From update of attachment 32266 [details]) > There are style issues in this patch: > > Spacing: > + for (var i = 16; i < 24; i++) { > + elements[i].draggable = i < 20; > + } > > Extra { > 151 } else if (equalIgnoringCase(value, "false")) { > 152 addCSSProperty(attr, CSSPropertyWebkitUserDrag, CSSValueNone); > 153 } > > Extra space: > 357 if (equalIgnoringCase(value , "true")) > > Those certainly could be corrected when landing. But having them here, makes > this hard to land automatically. I'll just fix them and ask for another review. Created attachment 32327 [details]
Style nits fixed
Can anyone submit this for me? I do not have commit rights. This changes the result of fast/dom/domListEnumeration.html but the patch doesn't include new results. I had to fix that myself. I'm concerned, because this should have showed up when you ran the regression tests yourself. (In reply to comment #15) > This changes the result of fast/dom/domListEnumeration.html but the patch > doesn't include new results. I had to fix that myself. I'm concerned, because > this should have showed up when you ran the regression tests yourself. My bad. Feel free to r- and I'll look into it |