| OLD | NEW | 
|---|
| 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  *           (C) 2000 Simon Hausmann (hausmann@kde.org) | 4  *           (C) 2000 Simon Hausmann (hausmann@kde.org) | 
| 5  *           (C) 2001 Dirk Mueller (mueller@kde.org) | 5  *           (C) 2001 Dirk Mueller (mueller@kde.org) | 
| 6  * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
     ed. | 6  * Copyright (C) 2004, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv
     ed. | 
| 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 13 matching lines...) Expand all  Loading... | 
| 24 #include "config.h" | 24 #include "config.h" | 
| 25 #include "core/html/HTMLBodyElement.h" | 25 #include "core/html/HTMLBodyElement.h" | 
| 26 | 26 | 
| 27 #include "bindings/core/v8/ScriptEventListener.h" | 27 #include "bindings/core/v8/ScriptEventListener.h" | 
| 28 #include "core/CSSValueKeywords.h" | 28 #include "core/CSSValueKeywords.h" | 
| 29 #include "core/HTMLNames.h" | 29 #include "core/HTMLNames.h" | 
| 30 #include "core/css/CSSImageValue.h" | 30 #include "core/css/CSSImageValue.h" | 
| 31 #include "core/css/StylePropertySet.h" | 31 #include "core/css/StylePropertySet.h" | 
| 32 #include "core/css/parser/CSSParser.h" | 32 #include "core/css/parser/CSSParser.h" | 
| 33 #include "core/dom/Attribute.h" | 33 #include "core/dom/Attribute.h" | 
| 34 #include "core/frame/FrameView.h" |  | 
| 35 #include "core/frame/LocalFrame.h" |  | 
| 36 #include "core/frame/ScrollToOptions.h" |  | 
| 37 #include "core/frame/UseCounter.h" | 34 #include "core/frame/UseCounter.h" | 
| 38 #include "core/html/HTMLFrameElementBase.h" | 35 #include "core/html/HTMLFrameElementBase.h" | 
| 39 #include "core/html/parser/HTMLParserIdioms.h" | 36 #include "core/html/parser/HTMLParserIdioms.h" | 
| 40 #include "core/layout/LayoutBox.h" |  | 
| 41 | 37 | 
| 42 namespace blink { | 38 namespace blink { | 
| 43 | 39 | 
| 44 using namespace HTMLNames; | 40 using namespace HTMLNames; | 
| 45 | 41 | 
| 46 inline HTMLBodyElement::HTMLBodyElement(Document& document) | 42 inline HTMLBodyElement::HTMLBodyElement(Document& document) | 
| 47     : HTMLElement(bodyTag, document) | 43     : HTMLElement(bodyTag, document) | 
| 48 { | 44 { | 
| 49 } | 45 } | 
| 50 | 46 | 
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 189     return backgroundAttr; | 185     return backgroundAttr; | 
| 190 } | 186 } | 
| 191 | 187 | 
| 192 bool HTMLBodyElement::supportsFocus() const | 188 bool HTMLBodyElement::supportsFocus() const | 
| 193 { | 189 { | 
| 194     // This override is needed because the inherited method bails if the parent 
     is editable. | 190     // This override is needed because the inherited method bails if the parent 
     is editable. | 
| 195     // The <body> should be focusable even if <html> is editable. | 191     // The <body> should be focusable even if <html> is editable. | 
| 196     return hasEditableStyle() || HTMLElement::supportsFocus(); | 192     return hasEditableStyle() || HTMLElement::supportsFocus(); | 
| 197 } | 193 } | 
| 198 | 194 | 
| 199 static int adjustForZoom(int value, Document* document) |  | 
| 200 { |  | 
| 201     LocalFrame* frame = document->frame(); |  | 
| 202     float zoomFactor = frame->pageZoomFactor(); |  | 
| 203     if (zoomFactor == 1) |  | 
| 204         return value; |  | 
| 205     // Needed because of truncation (rather than rounding) when scaling up. |  | 
| 206     if (zoomFactor > 1) |  | 
| 207         value++; |  | 
| 208     return static_cast<int>(value / zoomFactor); |  | 
| 209 } |  | 
| 210 |  | 
| 211 // Blink, Gecko and Presto's quirks mode implementations of overflow set to the |  | 
| 212 // body element differ from IE's: the formers can create a scrollable area for t
     he |  | 
| 213 // body element that is not the same as the root elements's one. On IE's quirks 
     mode |  | 
| 214 // though, as body is the root element, body's and the root element's scrollable
      areas, |  | 
| 215 // if any, are the same. |  | 
| 216 // In order words, a <body> will only have an overflow clip (that differs from |  | 
| 217 // documentElement's) if  both html and body nodes have its overflow set to eith
     er hidden, |  | 
| 218 // auto or scroll. |  | 
| 219 // That said, Blink's {set}scroll{Top,Left} behaviors match Gecko's: even if the
     re is a non-overflown |  | 
| 220 // scrollable area, scrolling should not get propagated to the viewport in neith
     er strict |  | 
| 221 // or quirks modes. |  | 
| 222 double HTMLBodyElement::scrollLeft() |  | 
| 223 { |  | 
| 224     Document& document = this->document(); |  | 
| 225     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 226 |  | 
| 227     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 228         LayoutBox* render = layoutBox(); |  | 
| 229         if (!render) |  | 
| 230             return 0; |  | 
| 231         if (render->hasOverflowClip()) |  | 
| 232             return adjustScrollForAbsoluteZoom(render->scrollLeft(), *render); |  | 
| 233         if (!document.inQuirksMode()) |  | 
| 234             return 0; |  | 
| 235     } |  | 
| 236 |  | 
| 237     if (LocalDOMWindow* window = document.domWindow()) |  | 
| 238         return window->scrollX(); |  | 
| 239     return 0; |  | 
| 240 } |  | 
| 241 |  | 
| 242 void HTMLBodyElement::setScrollLeft(double scrollLeft) |  | 
| 243 { |  | 
| 244     Document& document = this->document(); |  | 
| 245     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 246 |  | 
| 247     if (std::isnan(scrollLeft)) |  | 
| 248         return; |  | 
| 249 |  | 
| 250     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 251         LayoutBox* render = layoutBox(); |  | 
| 252         if (!render) |  | 
| 253             return; |  | 
| 254         if (render->hasOverflowClip()) { |  | 
| 255             // FIXME: Investigate how are other browsers casting to int (roundin
     g, ceiling, ...). |  | 
| 256             render->setScrollLeft(static_cast<int>(scrollLeft * render->style()-
     >effectiveZoom())); |  | 
| 257             return; |  | 
| 258         } |  | 
| 259         if (!document.inQuirksMode()) |  | 
| 260             return; |  | 
| 261     } |  | 
| 262 |  | 
| 263     if (LocalDOMWindow* window = document.domWindow()) |  | 
| 264         window->scrollTo(scrollLeft, window->scrollY()); |  | 
| 265 } |  | 
| 266 |  | 
| 267 double HTMLBodyElement::scrollTop() |  | 
| 268 { |  | 
| 269     Document& document = this->document(); |  | 
| 270     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 271 |  | 
| 272     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 273         LayoutBox* render = layoutBox(); |  | 
| 274         if (!render) |  | 
| 275             return 0; |  | 
| 276         if (render->hasOverflowClip()) |  | 
| 277             return adjustLayoutUnitForAbsoluteZoom(render->scrollTop(), *render)
     ; |  | 
| 278         if (!document.inQuirksMode()) |  | 
| 279             return 0; |  | 
| 280     } |  | 
| 281 |  | 
| 282     if (LocalDOMWindow* window = document.domWindow()) |  | 
| 283         return window->scrollY(); |  | 
| 284     return 0; |  | 
| 285 } |  | 
| 286 |  | 
| 287 void HTMLBodyElement::setScrollTop(double scrollTop) |  | 
| 288 { |  | 
| 289     Document& document = this->document(); |  | 
| 290     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 291 |  | 
| 292     if (std::isnan(scrollTop)) |  | 
| 293         return; |  | 
| 294 |  | 
| 295     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 296         LayoutBox* render = layoutBox(); |  | 
| 297         if (!render) |  | 
| 298             return; |  | 
| 299         if (render->hasOverflowClip()) { |  | 
| 300             // FIXME: Investigate how are other browsers casting to int (roundin
     g, ceiling, ...). |  | 
| 301             render->setScrollTop(static_cast<int>(scrollTop * render->style()->e
     ffectiveZoom())); |  | 
| 302             return; |  | 
| 303         } |  | 
| 304         if (!document.inQuirksMode()) |  | 
| 305             return; |  | 
| 306     } |  | 
| 307 |  | 
| 308     if (LocalDOMWindow* window = document.domWindow()) |  | 
| 309         window->scrollTo(window->scrollX(), scrollTop); |  | 
| 310 } |  | 
| 311 |  | 
| 312 int HTMLBodyElement::scrollHeight() |  | 
| 313 { |  | 
| 314     // Update the document's layout. |  | 
| 315     Document& document = this->document(); |  | 
| 316     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 317     FrameView* view = document.view(); |  | 
| 318     return view ? adjustForZoom(view->contentsHeight(), &document) : 0; |  | 
| 319 } |  | 
| 320 |  | 
| 321 int HTMLBodyElement::scrollWidth() |  | 
| 322 { |  | 
| 323     // Update the document's layout. |  | 
| 324     Document& document = this->document(); |  | 
| 325     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 326     FrameView* view = document.view(); |  | 
| 327     return view ? adjustForZoom(view->contentsWidth(), &document) : 0; |  | 
| 328 } |  | 
| 329 |  | 
| 330 void HTMLBodyElement::scrollBy(const ScrollToOptions& scrollToOptions) |  | 
| 331 { |  | 
| 332     Document& document = this->document(); |  | 
| 333 |  | 
| 334     // FIXME: This should be removed once scroll updates are processed only afte
     r |  | 
| 335     // the compositing update. See http://crbug.com/420741. |  | 
| 336     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 337 |  | 
| 338     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 339         LayoutBox* render = layoutBox(); |  | 
| 340         if (!render) |  | 
| 341             return; |  | 
| 342         if (render->hasOverflowClip()) { |  | 
| 343             scrollLayoutBoxBy(scrollToOptions); |  | 
| 344             return; |  | 
| 345         } |  | 
| 346         if (!document.inQuirksMode()) |  | 
| 347             return; |  | 
| 348     } |  | 
| 349 |  | 
| 350     scrollFrameBy(scrollToOptions); |  | 
| 351 } |  | 
| 352 |  | 
| 353 void HTMLBodyElement::scrollTo(const ScrollToOptions& scrollToOptions) |  | 
| 354 { |  | 
| 355     Document& document = this->document(); |  | 
| 356 |  | 
| 357     // FIXME: This should be removed once scroll updates are processed only afte
     r |  | 
| 358     // the compositing update. See http://crbug.com/420741. |  | 
| 359     document.updateLayoutIgnorePendingStylesheets(); |  | 
| 360 |  | 
| 361     if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { |  | 
| 362         LayoutBox* render = layoutBox(); |  | 
| 363         if (!render) |  | 
| 364             return; |  | 
| 365         if (render->hasOverflowClip()) { |  | 
| 366             scrollLayoutBoxTo(scrollToOptions); |  | 
| 367             return; |  | 
| 368         } |  | 
| 369         if (!document.inQuirksMode()) |  | 
| 370             return; |  | 
| 371     } |  | 
| 372 |  | 
| 373     scrollFrameTo(scrollToOptions); |  | 
| 374 } |  | 
| 375 |  | 
| 376 } // namespace blink | 195 } // namespace blink | 
| OLD | NEW | 
|---|