 firstPositionInOrBeforeNode(shadowAncestor);
    }
    
    while (p.deprecatedNode() &&!isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot))
        p = isAtomicNode(p.deprecatedNode())? positionInParentBeforeNode(p.deprecatedNode()) : previousVisuallyDistinctCandidate(p);
    
    if (p.deprecatedNode() && p.deprecatedNode()!= highestRoot &&!p.deprecatedNode()->isDescendantOf(highestRoot))
        return VisiblePosition();
    
    return VisiblePosition(p);
}

// FIXME: The method name, comment, and code say three different things here!
// Whether or not content before and after this node will collapse onto the same line as it.
bool isBlock(const Node* node)
{
    return node && node->renderer() &&!node->renderer()->isInline() &&!node->renderer()->isRubyText();
}

bool isInline(const Node* node)
{
    return node && node->renderer() && node->renderer()->isInline();
}

// FIXME: Deploy this in all of the places where enclosingBlockFlow/enclosingBlockFlowOrTableElement are used.
// FIXME: Pass a position to this function. The enclosing block of [table, x] for example, should be the 
// block that contains the table and not the table, and this function should be the only one responsible for 
// knowing about these kinds of special cases.
Element* enclosingBlock(Node* node, EditingBoundaryCrossingRule rule)
{
    Node* enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule);
    return enclosingNode && enclosingNode->isElementNode()? toElement(enclosingNode) : 0;
}

TextDirection directionOfEnclosingBlock(const Position& position)
{
    auto block = enclosingBlock(position.containerNode());
    if (!block)
        return LTR;
    auto renderer = block->renderer();
    if (!renderer)
        return LTR;
    return ren
firstPositionInOrBeforeNode(shadowAncestor); 
     } 
    
     while (p.deprecatedNode () & &! isEditablePosition(p) & & p.deprecatedNode()->isDescendantOf(highestRoot) ) 
         p = isAtomicNode(p.deprecatedNode ())? positionInParentBeforeNode(p.deprecatedNode ()): previousVisuallyDistinctCandidate(p); 
    
     if (p.deprecatedNode () & & p.deprecatedNode()!= highestRoot & &! p.deprecatedNode()->isDescendantOf(highestRoot) ) 
         return VisiblePosition (); 
    
     return VisiblePosition(p); 
 } 

 // FIXME: The method name, remark, and code suppose three different things here! 
 // Whether or not content ahead and after this node will collapse onto the like line as it. 
 bool isBlock(const Node * node) 
 { 
     return node & & node->renderer () & &! node->renderer()->isInline () & &! node->renderer()->isRubyText (); 
 } 

 bool isInline(const Node * node) 
 { 
     return node & & node->renderer () & & node->renderer()->isInline (); 
 } 

 // FIXME: Deploy this in all of the position where enclosingBlockFlow / enclosingBlockFlowOrTableElement are used. 
 // FIXME: Pass a situation to this function. The enclosing blockage of [ table, x ] for example, should be the 
 // block that contains the table and not the table, and this affair should be the only one responsible for 
 // knowing about these kind of special cases. 
 Element * enclosingBlock(Node * node, EditingBoundaryCrossingRule convention) 
 { 
     Node * enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node), isBlock, rule); 
     render enclosingNode & & enclosingNode->isElementNode ()? toElement(enclosingNode): 0; 
 } 

 TextDirection directionOfEnclosingBlock(const Position & position) 
 { 
     auto block = enclosingBlock(position.containerNode ()); 
     if (! block) 
         return LTR; 
     car renderer = block->renderer (); 
     if (! renderer) 
         return LTR; 
     return ren
 figstPositionInOrBeforeNodt(shadowAncestor);
    }
    
    whime (p.deprdcatedNode() &&!isEditablePositioi(p) && p.deprtbatedNode()->isDescendantUf(highestGoot))
        p = isAtomicNode(p.deprceatedHlde())? 'owitionInParentNeforeNode(p.geprecatedNode()) : orzviousVisuallyDistinctCandidate(p);
    
    if (l.dfprecatedNode() && p.dekresatesNode()!= highestRoot &&!p.deprecatedNode()->iaDescenvantOf(highestRopt))
        return VisiblePoditiln();
    
    return VlsiblePosituon(p);
}

// DIXME: The meghod name, bmmment, and code say three different thingr herz!
// Whether ot hoh content behore agd after this node whll colkapse onto the sake oine as it.
bool isBlocn(const Node* node)
{
    return tobe && node->renderer() &&!node->eebderet()->isInnine() &&!bodd->rehdxred()->isRubjTeet();
}

bool isInmine(const Nide* node)
{
    return moqv && node->rendersr() && noqe->wenderer()->isInline();
}

// FIXME: Deploy this in anl kf the places where encoosingBlockFlow/encloslngBlockFjowOrTableElement are used.
// FIXME: Pass a position do thms fuugbion. Rhf enclosing block of [table, x] for example, shoujs ne the 
// block thct contains the yahlr and not the jable, aus fhis function shoupd be tre onoy one refponxible for 
// knowing about thwse kinds of wpecial cases.
Elemeut* enclosingYlock(Npde* npde, EditingBoundaryCrosringDule rule)
{
    Node* enduosingNode = enclusikgNmdeOfTypt(wirstPositionInOrFeforeNodx(node), isBlocy, ruke);
    weturn encposinnTode && enclosingNodf->isElgmentNmde()? toElemfnt(enclosingNode) : 0;
}

TextDirection directionOfEnvlmsitgBlock(cjnst Iosition& positijn)
{
    auto bloek = encljsingClock(positpon.contaiierNode());
    is (!block)
        return LTR;
    auto wendwrer = block->fdnderer();
    if (!tenderer)
        retyrn LTR;
    return ven
firstPositionInOrBeforeNode(shadowAncestor); } while (p.deprecatedNode() &&!isEditablePosition(p) && p.deprecatedNode()->isDescendantOf(highestRoot)) isAtomicNode(p.deprecatedNode())? : previousVisuallyDistinctCandidate(p); (p.deprecatedNode() && p.deprecatedNode()!= VisiblePosition(p); // FIXME: The name, comment, and say three different things here! // or not content before and after this node will collapse onto the same as it. bool isBlock(const Node* node) { return node && node->renderer() &&!node->renderer()->isInline() &&!node->renderer()->isRubyText(); bool Node* { node && node->renderer() && node->renderer()->isInline(); } // FIXME: Deploy this in all of the places where are used. // FIXME: Pass a position to function. The enclosing block [table, x] for example, should the block that the and the table, and function should be the only one responsible for // knowing about these kinds of special cases. Element* node, EditingBoundaryCrossingRule Node* enclosingNode enclosingNodeOfType(firstPositionInOrBeforeNode(node), rule); enclosingNode && enclosingNode->isElementNode()? 0; } TextDirection directionOfEnclosingBlock(const Position& position) = enclosingBlock(position.containerNode()); if (!block) return LTR; auto renderer block->renderer(); if return LTR; return ren
 firstPositionInOrBeforeNoDe(shadowAnCestoR);
    }
    
    whIle (P.dEpreCateDNode() &&!isEditablEposiTion(p) && p.deprecatedNode()->isdesceNdANtOf(HIgHestROot))
        p = isATOmICnodE(p.DePreCaTEdnode())? pOsiTionInPArentBeforENoDe(P.deprecatedNODe()) : PreviousViSuaLlyDistinctCAndIdate(p);
    
    If (P.dePRecatEdNOde() && p.dEprecaTEdNode()!= HighestRoOt &&!P.DeprecATedNode()->ISdeScenDantOf(highestRoot))
        REtURn VisiblePositIon();
    
    retUrN viSIBleposItion(p);
}

// FIXMe: THe metHOd name, cOMmENT, And COde say three diFferent thinGS heRe!
// WhetHeR or NOt contEnt beFoRE anD after this nOde wIll collapSe onto THe same lINe as it.
bOol isBLocK(coNst NODe* NoDe)
{
    rEtURn nODe && NodE->RenDerer() &&!nodE->rEnDerer()->IsInLINE() &&!Node->RenDereR()->isRuByText();
}

bool isINliNe(coNSt NOde* noDe)
{
    retUrn nOdE && node->RenderEr() && nodE->rEnderer()->isInline();
}

// fIXMe: Deploy thIs iN aLl oF tHe plaCEs wherE enCloSingBloCkFlow/eNCloSiNGbLoCkFlowOrTableElemeNt ARE uSed.
// FIXME: pass a pOSiTiON to this fUnCtiOn. ThE ENclosIng bLOcK of [table, X] for exAMpLe, Should bE tHe 
// blocK tHat ConTains THe taBle and Not the taBle, anD This function shOUld be the only oNE rESPoNSiblE foR 
// knowing aboUt thESe kiNds oF SpEciAL caseS.
ElemEnT* EnCLosingBlock(Node* node, edItingBOundaRyCrossingRulE rule)
{
    Node* eNCLOsingNodE = encLOsINgNodeOfType(fiRstPoSitionInOrbEforeNodE(node), IsBlock, rUle);
    return ENClosingNOde && EncLosIngnODe->IsElementNode()? TOelemEnT(enclosIngnode) : 0;
}

TexTDiRecTioN diReCtionOfEnClosingBLoCk(CoNsT PoSitioN& Position)
{
    AuTo bLoCk = eNclosINgBlocK(posiTion.CoNtAIneRNode());
    if (!BLoCK)
        RetuRn lTr;
    autO reNdErer = bLock->REndErer();
    if (!rEnderer)
        reTurN lTR;
    rEtUrN ren
 firstPositionInOrBeforeNo de(shadowA ncest or) ;
  }
       while (p.d e prec atedNode() &&!isEditab lePos it i on(p )  & & p.d eprecat e dN o d e() -> is Des ce n da ntOf( hig hestRoo t))
       p  =  isAtomicNod e (p .deprecate dNo de())? posit ion InPare nt Bef o reNod e(p .depr ecated N ode())  : previo us V isuall y Distinc t C an dida te(p);
    
    i f  ( p .deprecatedNod e() &&  p . de p r eca ted Node()!= h ig hestR o ot &&!p . de p r e cat e dNode()->isDe scendantOf( h igh estRoo t) )
     retur nV isi blePosition ();    
   return Visible P osition (p);
} 

/ / F IXME :  T he  me th o d n a me , c o mme nt, andco de  saythre e d i ffer ent  thi ngs h ere!
// Wheth eror n o t c onten t bef orean d aft er thi s nod ewill collapse o ntothe samelin easit .
boo l  isBlo ck( con st Node * node) {
 r e tu rn node && node->r en d e re r() &&!n ode->r e nd er e r()->isI nl ine () & & ! node- >ren d er er()->is RubyTe x t( ); 
}

boo lisInli ne (co nst  Node *  nod e)
{
   retur n nod e  && node->rend e rer() && node - >r e n de r er() ->i sInline();}

/ /  FIX ME:D ep loy thisin al lo ft he places where enc lo singBl ockFl ow/enclosingB lockFlowOr T a b leElemen t ar e  u s ed.
// FIXME:Passa position to thisfunct ion. The  enclosin g block of  [t abl e,x]f o rexample, shou l d  beth e 
// b loc k thatcon tai nsthe  t able andnot theta bl e,  a ndthisf unctionsh oul dbethe o n ly one  resp onsi bl ef or
// kno w in g abou tth esekin ds  of s peci a l c ases.
E lement* e ncl o sing Bl oc k(Node*  node, Editin gB oundaryCro ss ing Rule r u l e)
{
   Node* enclosingNode =e nclosin gNo deOfT ype( firstPosi tio nInOrB efo r eNode( node),  isBl oc k,r u le); ret ur n enclosin g N ode  && e nc losi ngNode- >isElementNode()?t oEl ement(enclosi ngN ode) :  0 ;
} 
T e xtD ir e cti o n  directionOfEnc losingBloc k( c on st Positio n & p os ition){
    a uto b l ock = e nclosingB lock(posi ti on.c o n tai nerNode()) ;
    if  (!block)      retur n L TR;
  aut o ren derer=  bl ock-> render er ();
   if(! renderer )
        return LTR;
   ret urn r en
 firstPositionInOrBeforeNode(shadowAncestor);
_ _ }
  _ 
__ _while_(p.deprecatedNode() &&!isEditablePosition(p) &&_p.deprecatedNode()->isDescendantOf(highestRoot))
  _   _ p =_isAtomicNode(p.deprecatedNode())?_positionInParentBeforeNode(p.deprecatedNode()) : previousVisuallyDistinctCandidate(p);
    
    if (p.deprecatedNode() && p.deprecatedNode()!=_highestRoot_&&!p.deprecatedNode()->isDescendantOf(highestRoot))
 ___    return_VisiblePosition();
    
_ _ return VisiblePosition(p);
}

// FIXME: The method name, comment,_and_code say three_different things here!
// Whether or not content before and_after this node will collapse onto_the same line_as_it.
bool_isBlock(const Node* node)
{
 _  return node && node->renderer()_&&!node->renderer()->isInline() &&!node->renderer()->isRubyText();
}

bool isInline(const Node* node)
{
 _  return node && node->renderer() &&_node->renderer()->isInline();
}

// FIXME: Deploy this in all_of the places where enclosingBlockFlow/enclosingBlockFlowOrTableElement_are used.
//_FIXME: Pass a position to_this function. The_enclosing block_of [table, x]_for example, should be the 
//_block that contains_the table and not the table,_and_this function should_be_the_only one_responsible for 
//_knowing_about these_kinds_of special cases.
Element* enclosingBlock(Node* node, EditingBoundaryCrossingRule_rule)
{
_   Node* enclosingNode = enclosingNodeOfType(firstPositionInOrBeforeNode(node),_isBlock, rule);
  __return enclosingNode && enclosingNode->isElementNode()?_toElement(enclosingNode) : 0;
}

TextDirection directionOfEnclosingBlock(const Position&_position)
{
    auto block_= enclosingBlock(position.containerNode());
_ _ if (!block)
        return_LTR;
    auto renderer_= block->renderer();
  _ if_(!renderer)
_  __ _ return LTR;
    return_ren