@@ -102,6 +102,8 @@ public class MaterialCutOut extends MaterialWidget implements HasCloseHandlers<M
102102 private String viewportOverflow ;
103103 private Element targetElement ;
104104 private Element focusElement ;
105+ private boolean scrollIntoView = true ;
106+ private boolean absolute ;
105107 private int duration = 500 ;
106108
107109 public MaterialCutOut () {
@@ -130,12 +132,18 @@ public MaterialCutOut(Color backgroundColor, Boolean circle, Double opacity) {
130132 */
131133 @ Override
132134 public void open () {
135+ open (false );
136+ }
137+
138+ public void open (boolean absolute ) {
139+ this .absolute = absolute ;
140+
133141 setCutOutStyle ();
134142
135143 if (targetElement == null ) {
136144 throw new IllegalStateException ("The target element should be set before calling open()." );
137145 }
138- targetElement .scrollIntoView ();
146+ if ( scrollIntoView ) targetElement .scrollIntoView ();
139147
140148 if (computedBackgroundColor == null ) {
141149 setupComputedBackgroundColor ();
@@ -174,7 +182,7 @@ public void open() {
174182 focusElement .getStyle ().clearProperty ("webkitBorderTopLeftRadius" );
175183 focusElement .getStyle ().clearProperty ("borderTopLeftRadius" );
176184 }
177- setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle );
185+ setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle , absolute );
178186
179187 setupWindowHandlers ();
180188 getElement ().getStyle ().clearDisplay ();
@@ -377,8 +385,8 @@ public String getBackgroundSize() {
377385 /**
378386 * Setups the cut out position when the screen changes size or is scrolled.
379387 */
380- protected void setupCutOutPosition (Element cutOut , Element relativeTo , int padding , boolean circle ) {
381- float top = relativeTo .getOffsetTop () - (Math .max ($ ("html" ).scrollTop (), $ ("body" ).scrollTop ()));
388+ protected void setupCutOutPosition (Element cutOut , Element relativeTo , int padding , boolean circle , boolean absolute ) {
389+ float top = ( absolute ? relativeTo .getAbsoluteTop () : relativeTo . getOffsetTop () ) - (Math .max ($ ("html" ).scrollTop (), $ ("body" ).scrollTop ()));
382390 float left = relativeTo .getAbsoluteLeft ();
383391
384392 float width = relativeTo .getOffsetWidth ();
@@ -415,8 +423,8 @@ protected void setupCutOutPosition(Element cutOut, Element relativeTo, int paddi
415423 */
416424 protected void setupWindowHandlers () {
417425
418- registerHandler (Window .addResizeHandler (event -> setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle )));
419- registerHandler (Window .addWindowScrollHandler (event -> setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle )));
426+ registerHandler (Window .addResizeHandler (event -> setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle , absolute )));
427+ registerHandler (Window .addWindowScrollHandler (event -> setupCutOutPosition (focusElement , targetElement , cutOutPadding , circle , absolute )));
420428 }
421429
422430 protected void setupTransition () {
@@ -474,6 +482,14 @@ public int getDuration() {
474482 return duration ;
475483 }
476484
485+ public boolean isScrollIntoView () {
486+ return scrollIntoView ;
487+ }
488+
489+ public void setScrollIntoView (boolean scrollIntoView ) {
490+ this .scrollIntoView = scrollIntoView ;
491+ }
492+
477493 @ Override
478494 public HandlerRegistration addCloseHandler (final CloseHandler <MaterialCutOut > handler ) {
479495 return addHandler (handler , CloseEvent .getType ());
0 commit comments