1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
|
/*
* Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
* 1999 Lars Knoll <knoll@kde.org>
* 1999 Antti Koivisto <koivisto@kde.org>
* 2000 Dirk Mueller <mueller@kde.org>
* Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
* (C) 2006 Graham Dennis (graham.dennis@gmail.com)
* (C) 2006 Alexey Proskuryakov (ap@nypop.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "FrameView.h"
#include "AXObjectCache.h"
#include "CSSStyleSelector.h"
#include "ChromeClient.h"
#include "EventHandler.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameLoaderClient.h"
#include "GraphicsContext.h"
#include "HTMLDocument.h"
#include "HTMLFrameSetElement.h"
#include "HTMLNames.h"
#include "OverflowEvent.h"
#include "Page.h"
#include "RenderPart.h"
#include "RenderPartObject.h"
#include "RenderTheme.h"
#include "RenderView.h"
namespace WebCore {
using namespace HTMLNames;
struct ScheduledEvent {
RefPtr<Event> m_event;
RefPtr<EventTargetNode> m_eventTarget;
bool m_tempEvent;
};
class FrameViewPrivate {
public:
FrameViewPrivate(FrameView* view)
: m_slowRepaintObjectCount(0)
, layoutTimer(view, &FrameView::layoutTimerFired)
, layoutRoot(0)
, postLayoutTasksTimer(view, &FrameView::postLayoutTimerFired)
, m_mediaType("screen")
, m_enqueueEvents(0)
, m_overflowStatusDirty(true)
, m_viewportRenderer(0)
, m_wasScrolledByUser(false)
, m_inProgrammaticScroll(false)
{
isTransparent = false;
baseBackgroundColor = Color::white;
vmode = hmode = ScrollbarAuto;
needToInitScrollbars = true;
reset();
}
void reset()
{
useSlowRepaints = false;
borderX = 30;
borderY = 30;
layoutTimer.stop();
layoutRoot = 0;
delayedLayout = false;
doFullRepaint = true;
layoutSchedulingEnabled = true;
midLayout = false;
layoutCount = 0;
nestedLayoutCount = 0;
postLayoutTasksTimer.stop();
firstLayout = true;
m_wasScrolledByUser = false;
lastLayoutSize = IntSize();
lastZoomFactor = 1.0f;
m_deferringRepaints = 0;
m_repaintCount = 0;
m_repaintRect = IntRect();
m_repaintRects.clear();
}
bool doFullRepaint;
ScrollbarMode vmode;
ScrollbarMode hmode;
bool useSlowRepaints;
unsigned m_slowRepaintObjectCount;
int borderX, borderY;
Timer<FrameView> layoutTimer;
bool delayedLayout;
RenderObject* layoutRoot;
bool layoutSchedulingEnabled;
bool midLayout;
int layoutCount;
unsigned nestedLayoutCount;
Timer<FrameView> postLayoutTasksTimer;
bool firstLayout;
bool needToInitScrollbars;
bool isTransparent;
Color baseBackgroundColor;
IntSize lastLayoutSize;
float lastZoomFactor;
String m_mediaType;
unsigned m_enqueueEvents;
Vector<ScheduledEvent*> m_scheduledEvents;
bool m_overflowStatusDirty;
bool horizontalOverflow;
bool m_verticalOverflow;
RenderObject* m_viewportRenderer;
bool m_wasScrolledByUser;
bool m_inProgrammaticScroll;
unsigned m_deferringRepaints;
unsigned m_repaintCount;
IntRect m_repaintRect;
Vector<IntRect> m_repaintRects;
};
FrameView::FrameView(Frame* frame)
: m_refCount(1)
, m_frame(frame)
, d(new FrameViewPrivate(this))
{
init();
show();
}
#if !PLATFORM(MAC)
FrameView::FrameView(Frame* frame, const IntSize& initialSize)
: m_refCount(1)
, m_frame(frame)
, d(new FrameViewPrivate(this))
{
init();
Widget::setFrameGeometry(IntRect(x(), y(), initialSize.width(), initialSize.height()));
show();
}
#endif
FrameView::~FrameView()
{
if (d->postLayoutTasksTimer.isActive()) {
d->postLayoutTasksTimer.stop();
d->m_scheduledEvents.clear();
d->m_enqueueEvents = 0;
}
resetScrollbars();
ASSERT(m_refCount == 0);
ASSERT(d->m_scheduledEvents.isEmpty());
ASSERT(!d->m_enqueueEvents);
if (m_frame) {
ASSERT(m_frame->view() != this || !m_frame->document() || !m_frame->contentRenderer());
RenderPart* renderer = m_frame->ownerRenderer();
if (renderer && renderer->widget() == this)
renderer->setWidget(0);
}
delete d;
d = 0;
}
bool FrameView::isFrameView() const
{
return true;
}
void FrameView::clearFrame()
{
m_frame = 0;
}
void FrameView::resetScrollbars()
{
// Reset the document's scrollbars back to our defaults before we yield the floor.
d->firstLayout = true;
suppressScrollbars(true);
ScrollView::setVScrollbarMode(d->vmode);
ScrollView::setHScrollbarMode(d->hmode);
suppressScrollbars(false);
}
void FrameView::init()
{
m_margins = IntSize(-1, -1); // undefined
m_size = IntSize();
}
void FrameView::clear()
{
setStaticBackground(false);
d->reset();
if (m_frame)
if (RenderPart* renderer = m_frame->ownerRenderer())
renderer->viewCleared();
suppressScrollbars(true);
}
bool FrameView::didFirstLayout() const
{
return !d->firstLayout;
}
void FrameView::initScrollbars()
{
if (!d->needToInitScrollbars)
return;
d->needToInitScrollbars = false;
setScrollbarsMode(hScrollbarMode());
}
void FrameView::setMarginWidth(int w)
{
// make it update the rendering area when set
m_margins.setWidth(w);
}
void FrameView::setMarginHeight(int h)
{
// make it update the rendering area when set
m_margins.setHeight(h);
}
void FrameView::adjustViewSize()
{
ASSERT(m_frame->view() == this);
RenderView* root = m_frame->contentRenderer();
if (!root)
return;
resizeContents(root->overflowWidth(), root->overflowHeight());
}
void FrameView::applyOverflowToViewport(RenderObject* o, ScrollbarMode& hMode, ScrollbarMode& vMode)
{
// Handle the overflow:hidden/scroll case for the body/html elements. WinIE treats
// overflow:hidden and overflow:scroll on <body> as applying to the document's
// scrollbars. The CSS2.1 draft states that HTML UAs should use the <html> or <body> element and XML/XHTML UAs should
// use the root element.
switch (o->style()->overflowX()) {
case OHIDDEN:
hMode = ScrollbarAlwaysOff;
break;
case OSCROLL:
hMode = ScrollbarAlwaysOn;
break;
case OAUTO:
hMode = ScrollbarAuto;
break;
default:
// Don't set it at all.
;
}
switch (o->style()->overflowY()) {
case OHIDDEN:
vMode = ScrollbarAlwaysOff;
break;
case OSCROLL:
vMode = ScrollbarAlwaysOn;
break;
case OAUTO:
vMode = ScrollbarAuto;
break;
default:
// Don't set it at all.
;
}
d->m_viewportRenderer = o;
}
int FrameView::layoutCount() const
{
return d->layoutCount;
}
bool FrameView::needsFullRepaint() const
{
return d->doFullRepaint;
}
RenderObject* FrameView::layoutRoot(bool onlyDuringLayout) const
{
return onlyDuringLayout && layoutPending() ? 0 : d->layoutRoot;
}
void FrameView::layout(bool allowSubtree)
{
if (d->midLayout)
return;
d->layoutTimer.stop();
d->delayedLayout = false;
// Protect the view from being deleted during layout (in recalcStyle)
RefPtr<FrameView> protector(this);
if (!m_frame) {
// FIXME: Do we need to set m_size.width here?
// FIXME: Should we set m_size.height here too?
m_size.setWidth(visibleWidth());
return;
}
// we shouldn't enter layout() while painting
ASSERT(!m_frame->isPainting());
if (m_frame->isPainting())
return;
if (!allowSubtree && d->layoutRoot) {
d->layoutRoot->markContainingBlocksForLayout(false);
d->layoutRoot = 0;
}
ASSERT(m_frame->view() == this);
// This early return should be removed when rdar://5598072 is resolved. In the meantime, there is a
// gigantic CrashTracer because of this issue, and the early return will hopefully cause graceful
// failure instead.
if (m_frame->view() != this)
return;
Document* document = m_frame->document();
if (!document) {
// FIXME: Should we set m_size.height here too?
m_size.setWidth(visibleWidth());
return;
}
d->layoutSchedulingEnabled = false;
if (!d->nestedLayoutCount && d->postLayoutTasksTimer.isActive()) {
// This is a new top-level layout. If there are any remaining tasks from the previous
// layout, finish them now.
d->postLayoutTasksTimer.stop();
performPostLayoutTasks();
}
// Viewport-dependent media queries may cause us to need completely different style information.
// Check that here.
if (document->styleSelector()->affectedByViewportChange())
document->updateStyleSelector();
// Always ensure our style info is up-to-date. This can happen in situations where
// the layout beats any sort of style recalc update that needs to occur.
if (m_frame->needsReapplyStyles())
m_frame->reapplyStyles();
else if (document->hasChangedChild())
document->recalcStyle();
bool subtree = d->layoutRoot;
// If there is only one ref to this view left, then its going to be destroyed as soon as we exit,
// so there's no point to continuing to layout
if (protector->hasOneRef())
return;
RenderObject* root = subtree ? d->layoutRoot : document->renderer();
if (!root) {
// FIXME: Do we need to set m_size here?
d->layoutSchedulingEnabled = true;
return;
}
d->nestedLayoutCount++;
ScrollbarMode hMode = d->hmode;
ScrollbarMode vMode = d->vmode;
if (!subtree) {
RenderObject* rootRenderer = document->documentElement() ? document->documentElement()->renderer() : 0;
if (document->isHTMLDocument()) {
Node* body = static_cast<HTMLDocument*>(document)->body();
if (body && body->renderer()) {
if (body->hasTagName(framesetTag)) {
body->renderer()->setChildNeedsLayout(true);
vMode = ScrollbarAlwaysOff;
hMode = ScrollbarAlwaysOff;
} else if (body->hasTagName(bodyTag)) {
if (!d->firstLayout && m_size.height() != visibleHeight()
&& static_cast<RenderBox*>(body->renderer())->stretchesToViewHeight())
body->renderer()->setChildNeedsLayout(true);
// It's sufficient to just check the X overflow,
// since it's illegal to have visible in only one direction.
RenderObject* o = rootRenderer->style()->overflowX() == OVISIBLE
? body->renderer() : rootRenderer;
applyOverflowToViewport(o, hMode, vMode); // Only applies to HTML UAs, not to XML/XHTML UAs
}
}
} else if (rootRenderer)
applyOverflowToViewport(rootRenderer, hMode, vMode); // XML/XHTML UAs use the root element.
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (d->firstLayout && !document->ownerElement())
printf("Elapsed time before first layout: %d\n", document->elapsedTime());
#endif
}
d->doFullRepaint = !subtree && (d->firstLayout || static_cast<RenderView*>(root)->printing());
bool didFirstLayout = false;
if (!subtree) {
// Now set our scrollbar state for the layout.
ScrollbarMode currentHMode = hScrollbarMode();
ScrollbarMode currentVMode = vScrollbarMode();
if (d->firstLayout || (hMode != currentHMode || vMode != currentVMode)) {
suppressScrollbars(true);
if (d->firstLayout) {
d->firstLayout = false;
didFirstLayout = true;
d->lastLayoutSize = IntSize(width(), height());
d->lastZoomFactor = root->style()->zoom();
// Set the initial vMode to AlwaysOn if we're auto.
if (vMode == ScrollbarAuto)
ScrollView::setVScrollbarMode(ScrollbarAlwaysOn); // This causes a vertical scrollbar to appear.
// Set the initial hMode to AlwaysOff if we're auto.
if (hMode == ScrollbarAuto)
ScrollView::setHScrollbarMode(ScrollbarAlwaysOff); // This causes a horizontal scrollbar to disappear.
}
if (hMode == vMode)
ScrollView::setScrollbarsMode(hMode);
else {
ScrollView::setHScrollbarMode(hMode);
ScrollView::setVScrollbarMode(vMode);
}
suppressScrollbars(false, true);
}
IntSize oldSize = m_size;
m_size = IntSize(visibleWidth(), visibleHeight());
if (oldSize != m_size)
d->doFullRepaint = true;
}
RenderLayer* layer = root->enclosingLayer();
pauseScheduledEvents();
if (subtree)
root->view()->pushLayoutState(root);
d->midLayout = true;
beginDeferredRepaints();
root->layout();
endDeferredRepaints();
d->midLayout = false;
if (subtree)
root->view()->popLayoutState();
d->layoutRoot = 0;
m_frame->invalidateSelection();
d->layoutSchedulingEnabled = true;
if (!subtree && !static_cast<RenderView*>(root)->printing())
adjustViewSize();
// Now update the positions of all layers.
beginDeferredRepaints();
layer->updateLayerPositions(d->doFullRepaint);
endDeferredRepaints();
d->layoutCount++;
#if PLATFORM(MAC)
if (AXObjectCache::accessibilityEnabled())
root->document()->axObjectCache()->postNotificationToElement(root, "AXLayoutComplete");
#endif
#if ENABLE(DASHBOARD_SUPPORT)
updateDashboardRegions();
#endif
if (didFirstLayout)
m_frame->loader()->didFirstLayout();
ASSERT(!root->needsLayout());
setStaticBackground(useSlowRepaints());
if (document->hasListenerType(Document::OVERFLOWCHANGED_LISTENER))
updateOverflowStatus(visibleWidth() < contentsWidth(),
visibleHeight() < contentsHeight());
if (!d->postLayoutTasksTimer.isActive()) {
// Calls resumeScheduledEvents()
performPostLayoutTasks();
if (needsLayout()) {
// Post-layout widget updates or an event handler made us need layout again.
// Lay out again, but this time defer widget updates and event dispatch until after
// we return.
d->postLayoutTasksTimer.startOneShot(0);
pauseScheduledEvents();
layout();
}
} else {
resumeScheduledEvents();
ASSERT(d->m_enqueueEvents);
}
d->nestedLayoutCount--;
}
void FrameView::addWidgetToUpdate(RenderPartObject* object)
{
if (!m_widgetUpdateSet)
m_widgetUpdateSet.set(new HashSet<RenderPartObject*>);
m_widgetUpdateSet->add(object);
}
void FrameView::removeWidgetToUpdate(RenderPartObject* object)
{
if (!m_widgetUpdateSet)
return;
m_widgetUpdateSet->remove(object);
}
//
// Event Handling
//
/////////////////
bool FrameView::scrollTo(const IntRect& bounds)
{
int x, y, xe, ye;
x = bounds.x();
y = bounds.y();
xe = bounds.right() - 1;
ye = bounds.bottom() - 1;
int deltax;
int deltay;
int curHeight = visibleHeight();
int curWidth = visibleWidth();
if (ye - y>curHeight-d->borderY)
ye = y + curHeight - d->borderY;
if (xe - x>curWidth-d->borderX)
xe = x + curWidth - d->borderX;
// is xpos of target left of the view's border?
if (x < contentsX() + d->borderX)
deltax = x - contentsX() - d->borderX;
// is xpos of target right of the view's right border?
else if (xe + d->borderX > contentsX() + curWidth)
deltax = xe + d->borderX - (contentsX() + curWidth);
else
deltax = 0;
// is ypos of target above upper border?
if (y < contentsY() + d->borderY)
deltay = y - contentsY() - d->borderY;
// is ypos of target below lower border?
else if (ye + d->borderY > contentsY() + curHeight)
deltay = ye + d->borderY - (contentsY() + curHeight);
else
deltay = 0;
int maxx = curWidth - d->borderX;
int maxy = curHeight - d->borderY;
int scrollX = deltax > 0 ? (deltax > maxx ? maxx : deltax) : deltax == 0 ? 0 : (deltax > -maxx ? deltax : -maxx);
int scrollY = deltay > 0 ? (deltay > maxy ? maxy : deltay) : deltay == 0 ? 0 : (deltay > -maxy ? deltay : -maxy);
if (contentsX() + scrollX < 0)
scrollX = -contentsX();
else if (contentsWidth() - visibleWidth() - contentsX() < scrollX)
scrollX = contentsWidth() - visibleWidth() - contentsX();
if (contentsY() + scrollY < 0)
scrollY = -contentsY();
else if (contentsHeight() - visibleHeight() - contentsY() < scrollY)
scrollY = contentsHeight() - visibleHeight() - contentsY();
scrollBy(scrollX, scrollY);
// generate abs(scroll.)
if (scrollX < 0)
scrollX = -scrollX;
if (scrollY < 0)
scrollY = -scrollY;
return scrollX != maxx && scrollY != maxy;
}
void FrameView::setMediaType(const String& mediaType)
{
d->m_mediaType = mediaType;
}
String FrameView::mediaType() const
{
// See if we have an override type.
String overrideType = m_frame->loader()->client()->overrideMediaType();
if (!overrideType.isNull())
return overrideType;
return d->m_mediaType;
}
bool FrameView::useSlowRepaints() const
{
return d->useSlowRepaints || d->m_slowRepaintObjectCount > 0;
}
void FrameView::setUseSlowRepaints()
{
d->useSlowRepaints = true;
setStaticBackground(true);
}
void FrameView::addSlowRepaintObject()
{
if (!d->m_slowRepaintObjectCount)
setStaticBackground(true);
d->m_slowRepaintObjectCount++;
}
void FrameView::removeSlowRepaintObject()
{
ASSERT(d->m_slowRepaintObjectCount > 0);
d->m_slowRepaintObjectCount--;
if (!d->m_slowRepaintObjectCount)
setStaticBackground(d->useSlowRepaints);
}
void FrameView::setScrollbarsMode(ScrollbarMode mode)
{
d->vmode = mode;
d->hmode = mode;
ScrollView::setScrollbarsMode(mode);
}
void FrameView::setVScrollbarMode(ScrollbarMode mode)
{
d->vmode = mode;
ScrollView::setVScrollbarMode(mode);
}
void FrameView::setHScrollbarMode(ScrollbarMode mode)
{
d->hmode = mode;
ScrollView::setHScrollbarMode(mode);
}
void FrameView::restoreScrollbar()
{
suppressScrollbars(false);
}
void FrameView::scrollRectIntoViewRecursively(const IntRect& r)
{
if (frame()->prohibitsScrolling())
return;
bool wasInProgrammaticScroll = d->m_inProgrammaticScroll;
d->m_inProgrammaticScroll = true;
ScrollView::scrollRectIntoViewRecursively(r);
d->m_inProgrammaticScroll = wasInProgrammaticScroll;
}
void FrameView::setContentsPos(int x, int y)
{
if (frame()->prohibitsScrolling())
return;
bool wasInProgrammaticScroll = d->m_inProgrammaticScroll;
d->m_inProgrammaticScroll = true;
ScrollView::setContentsPos(x, y);
d->m_inProgrammaticScroll = wasInProgrammaticScroll;
}
const unsigned cRepaintRectUnionThreshold = 25;
void FrameView::repaintRectangle(const IntRect& r, bool immediate)
{
if (d->m_deferringRepaints && !immediate) {
IntRect visibleContent = enclosingIntRect(visibleContentRect());
visibleContent.intersect(r);
if (!visibleContent.isEmpty()) {
d->m_repaintCount++;
d->m_repaintRect.unite(r);
if (d->m_repaintCount == cRepaintRectUnionThreshold)
d->m_repaintRects.clear();
else if (d->m_repaintCount < cRepaintRectUnionThreshold)
d->m_repaintRects.append(r);
}
return;
}
updateContents(r, immediate);
}
void FrameView::beginDeferredRepaints()
{
Page* page = m_frame->page();
if (page->mainFrame() != m_frame)
return page->mainFrame()->view()->beginDeferredRepaints();
d->m_deferringRepaints++;
d->m_repaintCount = 0;
d->m_repaintRect = IntRect();
d->m_repaintRects.clear();
}
void FrameView::endDeferredRepaints()
{
Page* page = m_frame->page();
if (page->mainFrame() != m_frame)
return page->mainFrame()->view()->endDeferredRepaints();
ASSERT(d->m_deferringRepaints > 0);
if (--d->m_deferringRepaints == 0) {
if (d->m_repaintCount >= cRepaintRectUnionThreshold)
repaintRectangle(d->m_repaintRect, false);
else {
unsigned size = d->m_repaintRects.size();
for (unsigned i = 0; i < size; i++)
repaintRectangle(d->m_repaintRects[i], false);
d->m_repaintRects.clear();
}
}
}
void FrameView::layoutTimerFired(Timer<FrameView>*)
{
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (m_frame->document() && !m_frame->document()->ownerElement())
printf("Layout timer fired at %d\n", m_frame->document()->elapsedTime());
#endif
layout();
}
void FrameView::scheduleRelayout()
{
ASSERT(!m_frame->document() || !m_frame->document()->inPageCache());
ASSERT(m_frame->view() == this);
if (d->layoutRoot) {
d->layoutRoot->markContainingBlocksForLayout(false);
d->layoutRoot = 0;
}
if (!d->layoutSchedulingEnabled)
return;
if (!m_frame->document() || !m_frame->document()->shouldScheduleLayout())
return;
int delay = m_frame->document()->minimumLayoutDelay();
if (d->layoutTimer.isActive() && d->delayedLayout && !delay)
unscheduleRelayout();
if (d->layoutTimer.isActive())
return;
d->delayedLayout = delay != 0;
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (!m_frame->document()->ownerElement())
printf("Scheduling layout for %d\n", delay);
#endif
d->layoutTimer.startOneShot(delay * 0.001);
}
static bool isObjectAncestorContainerOf(RenderObject* ancestor, RenderObject* descendant)
{
for (RenderObject* r = descendant; r; r = r->container()) {
if (r == ancestor)
return true;
}
return false;
}
void FrameView::scheduleRelayoutOfSubtree(RenderObject* relayoutRoot)
{
ASSERT(m_frame->view() == this);
if (!d->layoutSchedulingEnabled || (m_frame->contentRenderer()
&& m_frame->contentRenderer()->needsLayout())) {
if (relayoutRoot)
relayoutRoot->markContainingBlocksForLayout(false);
return;
}
if (layoutPending()) {
if (d->layoutRoot != relayoutRoot) {
if (isObjectAncestorContainerOf(d->layoutRoot, relayoutRoot)) {
// Keep the current root
relayoutRoot->markContainingBlocksForLayout(false, d->layoutRoot);
} else if (d->layoutRoot && isObjectAncestorContainerOf(relayoutRoot, d->layoutRoot)) {
// Re-root at relayoutRoot
d->layoutRoot->markContainingBlocksForLayout(false, relayoutRoot);
d->layoutRoot = relayoutRoot;
} else {
// Just do a full relayout
if (d->layoutRoot)
d->layoutRoot->markContainingBlocksForLayout(false);
d->layoutRoot = 0;
relayoutRoot->markContainingBlocksForLayout(false);
}
}
} else {
int delay = m_frame->document()->minimumLayoutDelay();
d->layoutRoot = relayoutRoot;
d->delayedLayout = delay != 0;
d->layoutTimer.startOneShot(delay * 0.001);
}
}
bool FrameView::layoutPending() const
{
return d->layoutTimer.isActive();
}
bool FrameView::needsLayout() const
{
// It is possible that our document will not have a body yet. If this is the case,
// then we are not allowed to schedule layouts yet, so we won't be pending layout.
if (!m_frame)
return false;
RenderView* root = m_frame->contentRenderer();
Document * doc = m_frame->document();
// doc->hasChangedChild() condition can occur when using WebKit ObjC interface
return layoutPending() || (root && root->needsLayout()) || d->layoutRoot || (doc && doc->hasChangedChild()) || m_frame->needsReapplyStyles();
}
void FrameView::setNeedsLayout()
{
RenderView* root = m_frame->contentRenderer();
if (root)
root->setNeedsLayout(true);
}
void FrameView::unscheduleRelayout()
{
if (!d->layoutTimer.isActive())
return;
#ifdef INSTRUMENT_LAYOUT_SCHEDULING
if (m_frame->document() && !m_frame->document()->ownerElement())
printf("Layout timer unscheduled at %d\n", m_frame->document()->elapsedTime());
#endif
d->layoutTimer.stop();
d->delayedLayout = false;
}
bool FrameView::isTransparent() const
{
return d->isTransparent;
}
void FrameView::setTransparent(bool isTransparent)
{
d->isTransparent = isTransparent;
}
Color FrameView::baseBackgroundColor() const
{
return d->baseBackgroundColor;
}
void FrameView::setBaseBackgroundColor(Color bc)
{
if (!bc.isValid())
bc = Color::white;
d->baseBackgroundColor = bc;
}
void FrameView::scheduleEvent(PassRefPtr<Event> event, PassRefPtr<EventTargetNode> eventTarget, bool tempEvent)
{
if (!d->m_enqueueEvents) {
ExceptionCode ec = 0;
eventTarget->dispatchEvent(event, ec, tempEvent);
return;
}
ScheduledEvent* scheduledEvent = new ScheduledEvent;
scheduledEvent->m_event = event;
scheduledEvent->m_eventTarget = eventTarget;
scheduledEvent->m_tempEvent = tempEvent;
d->m_scheduledEvents.append(scheduledEvent);
}
void FrameView::pauseScheduledEvents()
{
ASSERT(d->m_scheduledEvents.isEmpty() || d->m_enqueueEvents);
d->m_enqueueEvents++;
}
void FrameView::resumeScheduledEvents()
{
d->m_enqueueEvents--;
if (!d->m_enqueueEvents)
dispatchScheduledEvents();
ASSERT(d->m_scheduledEvents.isEmpty() || d->m_enqueueEvents);
}
void FrameView::performPostLayoutTasks()
{
RenderView* root = m_frame->contentRenderer();
root->updateWidgetPositions();
if (m_widgetUpdateSet && d->nestedLayoutCount <= 1) {
Vector<RenderPartObject*> objectVector;
copyToVector(*m_widgetUpdateSet, objectVector);
size_t size = objectVector.size();
for (size_t i = 0; i < size; ++i) {
RenderPartObject* object = objectVector[i];
object->updateWidget(false);
// updateWidget() can destroy the RenderPartObject, so we need to make sure it's
// alive by checking if it's still in m_widgetUpdateSet.
if (m_widgetUpdateSet->contains(object))
object->updateWidgetPosition();
}
m_widgetUpdateSet->clear();
}
resumeScheduledEvents();
if (!root->printing()) {
IntSize currentSize = IntSize(width(), height());
float currentZoomFactor = root->style()->zoom();
bool resized = !d->firstLayout && (currentSize != d->lastLayoutSize || currentZoomFactor != d->lastZoomFactor);
d->lastLayoutSize = currentSize;
d->lastZoomFactor = currentZoomFactor;
if (resized)
m_frame->sendResizeEvent();
}
}
void FrameView::postLayoutTimerFired(Timer<FrameView>*)
{
performPostLayoutTasks();
}
void FrameView::updateOverflowStatus(bool horizontalOverflow, bool verticalOverflow)
{
if (!d->m_viewportRenderer)
return;
if (d->m_overflowStatusDirty) {
d->horizontalOverflow = horizontalOverflow;
d->m_verticalOverflow = verticalOverflow;
d->m_overflowStatusDirty = false;
return;
}
bool horizontalOverflowChanged = (d->horizontalOverflow != horizontalOverflow);
bool verticalOverflowChanged = (d->m_verticalOverflow != verticalOverflow);
if (horizontalOverflowChanged || verticalOverflowChanged) {
d->horizontalOverflow = horizontalOverflow;
d->m_verticalOverflow = verticalOverflow;
scheduleEvent(OverflowEvent::create(horizontalOverflowChanged, horizontalOverflow,
verticalOverflowChanged, verticalOverflow),
EventTargetNodeCast(d->m_viewportRenderer->element()), true);
}
}
void FrameView::dispatchScheduledEvents()
{
if (d->m_scheduledEvents.isEmpty())
return;
Vector<ScheduledEvent*> scheduledEventsCopy = d->m_scheduledEvents;
d->m_scheduledEvents.clear();
Vector<ScheduledEvent*>::iterator end = scheduledEventsCopy.end();
for (Vector<ScheduledEvent*>::iterator it = scheduledEventsCopy.begin(); it != end; ++it) {
ScheduledEvent* scheduledEvent = *it;
ExceptionCode ec = 0;
// Only dispatch events to nodes that are in the document
if (scheduledEvent->m_eventTarget->inDocument())
scheduledEvent->m_eventTarget->dispatchEvent(scheduledEvent->m_event,
ec, scheduledEvent->m_tempEvent);
delete scheduledEvent;
}
}
IntRect FrameView::windowClipRect() const
{
return windowClipRect(true);
}
IntRect FrameView::windowClipRect(bool clipToContents) const
{
ASSERT(m_frame->view() == this);
// Set our clip rect to be our contents.
IntRect clipRect;
if (clipToContents)
clipRect = enclosingIntRect(visibleContentRect());
else
clipRect = IntRect(contentsX(), contentsY(), width(), height());
clipRect = contentsToWindow(clipRect);
if (!m_frame || !m_frame->document() || !m_frame->document()->ownerElement())
return clipRect;
// Take our owner element and get the clip rect from the enclosing layer.
Element* elt = m_frame->document()->ownerElement();
RenderLayer* layer = elt->renderer()->enclosingLayer();
// FIXME: layer should never be null, but sometimes seems to be anyway.
if (!layer)
return clipRect;
FrameView* parentView = elt->document()->view();
clipRect.intersect(parentView->windowClipRectForLayer(layer, true));
return clipRect;
}
IntRect FrameView::windowClipRectForLayer(const RenderLayer* layer, bool clipToLayerContents) const
{
// If we have no layer, just return our window clip rect.
if (!layer)
return windowClipRect();
// Apply the clip from the layer.
IntRect clipRect;
if (clipToLayerContents)
clipRect = layer->childrenClipRect();
else
clipRect = layer->selfClipRect();
clipRect = contentsToWindow(clipRect);
return intersection(clipRect, windowClipRect());
}
#if ENABLE(DASHBOARD_SUPPORT)
void FrameView::updateDashboardRegions()
{
Document* document = m_frame->document();
if (!document->hasDashboardRegions())
return;
Vector<DashboardRegionValue> newRegions;
document->renderer()->collectDashboardRegions(newRegions);
if (newRegions == document->dashboardRegions())
return;
document->setDashboardRegions(newRegions);
Page* page = m_frame->page();
if (!page)
return;
page->chrome()->client()->dashboardRegionsChanged();
}
#endif
void FrameView::updateControlTints()
{
// This is called when control tints are changed from aqua/graphite to clear and vice versa.
// We do a "fake" paint, and when the theme gets a paint call, it can then do an invalidate.
// This is only done if the theme supports control tinting. It's up to the theme and platform
// to define when controls get the tint and to call this function when that changes.
// Optimize the common case where we bring a window to the front while it's still empty.
if (!m_frame || m_frame->loader()->url().isEmpty())
return;
if (theme()->supportsControlTints() && m_frame->contentRenderer()) {
if (needsLayout())
layout();
PlatformGraphicsContext* const noContext = 0;
GraphicsContext context(noContext);
context.setUpdatingControlTints(true);
#if !PLATFORM(MAC)
ScrollView::paint(&context, frameGeometry());
#else
m_frame->paint(&context, enclosingIntRect(visibleContentRect()));
#endif
}
}
bool FrameView::wasScrolledByUser() const
{
return d->m_wasScrolledByUser;
}
void FrameView::setWasScrolledByUser(bool wasScrolledByUser)
{
if (d->m_inProgrammaticScroll)
return;
d->m_wasScrolledByUser = wasScrolledByUser;
}
#if PLATFORM(WIN) || PLATFORM(GTK) || PLATFORM(QT)
void FrameView::layoutIfNeededRecursive()
{
// We have to crawl our entire tree looking for any FrameViews that need
// layout and make sure they are up to date.
// Mac actually tests for intersection with the dirty region and tries not to
// update layout for frames that are outside the dirty region. Not only does this seem
// pointless (since those frames will have set a zero timer to layout anyway), but
// it is also incorrect, since if two frames overlap, the first could be excluded from the dirty
// region but then become included later by the second frame adding rects to the dirty region
// when it lays out.
if (needsLayout())
layout();
HashSet<Widget*>* viewChildren = children();
HashSet<Widget*>::iterator end = viewChildren->end();
for (HashSet<Widget*>::iterator current = viewChildren->begin(); current != end; ++current)
if ((*current)->isFrameView())
static_cast<FrameView*>(*current)->layoutIfNeededRecursive();
}
#endif
}
|