/* Ċ Ġ* ĠCopyright Ġ 2 0 1 7 ĠN ich olas ĠB ily k Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* ĠĠĠĠ Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ package Ġcom . ac orn ui . core . focus Ċ Ċ import Ġcom . ac orn ui . component . Ui Component Ro Ċ import Ġcom . ac orn ui . component . create Or Re use Attachment Ċ import Ġcom . ac orn ui . core . Disposable Ċ import Ġcom . ac orn ui . core . di . inject Ċ import Ġcom . ac orn ui . core . di . own s Ċ import Ġcom . ac orn ui . signal . Signal Ċ import Ġcom . ac orn ui . signal . Signal 0 Ċ Ċ class ĠFocus Attachment ( Ċĉ ĉ private Ġval Ġtarget : ĠUi Component Ro Ċ ) Ġ: ĠDis posable Ġ{ ĊĊ ĉ private Ġval Ġfocus Manager Ġ= Ġtarget . inject ( Focus Manager ) ĊĊ ĉ private Ġval Ġ_ focused Ġ= ĠSignal 0 () Ċ ĉ val Ġfocused Ġ= Ġ_ focused . as Ro () ĊĊ ĉ private Ġval Ġ_ focused Self Ġ= ĠSignal 0 () ĊĊ ĉ /** Ċĉ Ġ* ĠDis patched Ġwhen Ġthis Ġcomponent Ġbecomes Ġthe Ġnewly Ġfocused Ġcomponent . Ġ( Not Ġincluding Ġif Ġan Ġowned Ġcomponent Ġbecomes Ġfocused ) Ċĉ Ġ* Ġ@ see Ġis Focused Self Ċĉ Ġ* Ġ@ see ĠFocus Manager . focused Ċĉ Ġ* Ġ@ see Ġfocused Ċĉ Ġ*/ Ċ ĉ val Ġfocused Self Ġ= Ġ_ focused Self . as Ro () ĊĊ ĉ private Ġval Ġ_ bl urred Ġ= ĠSignal 0 () ĊĊ ĉ /** Ċĉ Ġ* ĠDis patched Ġwhen Ġthis Ġcomponent Ġwas Ġpreviously Ġfocused , Ġand Ġafter Ġa Ġfocus Ġchange Ġthis Ġcomponent Ġthen Ġowns Ġthe Ċĉ Ġ* Ġnewly Ġfocused Ġcomponent . Ċĉ Ġ* Ġ@ see Ġis Focused Ċĉ Ġ* Ġ@ see ĠFocus Manager . focused Ċĉ Ġ*/ Ċ ĉ val Ġbl urred Ġ= Ġ_ bl urred . as Ro () ĊĊ ĉ private Ġval Ġ_ bl urred Self Ġ= ĠSignal 0 () ĊĊ ĉ /** Ċĉ Ġ* ĠDis patched Ġwhen Ġthis Ġcomponent Ġlo ses Ġfocus . Ġ( In cluding Ġlo sing Ġfocus Ġto Ġan Ġowned Ġcomponent ) Ċĉ Ġ* Ġ@ see Ġis Focused Self Ċĉ Ġ* Ġ@ see ĠFocus Manager . focused Ċĉ Ġ* Ġ@ see Ġbl urred Ċĉ Ġ*/ Ċ ĉ val Ġbl urred Self Ġ= Ġ_ bl urred Self . as Ro () ĊĊ ĉ init Ġ{ Ċĉ ĉ focus Manager . focused Changed . add (:: focus Changed Handler ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġfocus Changed Handler ( old : ĠUi Component Ro ?, Ġnew : ĠUi Component Ro ?) Ġ{ Ċĉ ĉ if Ġ(_ focused Self . isNotEmpty () Ġ&& Ġnew Ġ=== Ġtarget Ġ&& Ġold Ġ!== Ġtarget ) Ċĉĉ ĉ _ focused Self . dispatch () Ċĉ ĉ if Ġ(_ bl urred Self . isNotEmpty () Ġ&& Ġold Ġ=== Ġtarget Ġ&& Ġnew Ġ!== Ġtarget ) Ċĉĉ ĉ _ bl urred Self . dispatch () Ċĉ ĉ if Ġ(_ bl urred . isNotEmpty () Ġ&& Ġtarget . own s ( old ) Ġ&& Ġ! target . own s ( new )) Ċĉĉ ĉ _ bl urred . dispatch () Ċĉ ĉ if Ġ(_ focused . isNotEmpty () Ġ&& Ġ! target . own s ( old ) Ġ&& Ġtarget . own s ( new )) Ċĉĉ ĉ _ focused . dispatch () Ċ ĉ } ĊĊ ĉ override Ġfun Ġdispose () Ġ{ Ċĉ ĉ focus Manager . focused Changed . remove (:: focus Changed Handler ) Ċĉ ĉ _ focused . dispose () Ċĉ ĉ _ focused Self . dispose () Ċĉ ĉ _ bl urred . dispose () Ċĉ ĉ _ bl urred Self . dispose () Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ċ } Ċ Ċ fun ĠUi Component Ro . focus Attachment (): ĠFocus Attachment Ġ{ Ċ ĉ return Ġcreate Or Re use Attachment ( Focus Attachment ) Ġ{ ĠFocus Attachment ( this ) Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠDis patched Ġwhen Ġthis Ġcomponent Ġwas Ġpreviously Ġnot Ġfocused , Ġand Ġafter Ġa Ġfocus Ġchange Ġthis Ġcomponent Ġthen Ġowns Ġthe Ċ Ġ* Ġnewly Ġfocused Ġcomponent . Ċ Ġ* Ġ@ see Ġis Focused Ċ Ġ*/ Ċ fun ĠUi Component Ro . focused (): ĠSignal < () Ġ-> ĠUnit > Ġ{ Ċ ĉ return Ġfocus Attachment (). focused Ċ } Ċ Ċ /** Ċ Ġ* Ġ@ see ĠFocus Attachment . bl urred Ċ Ġ*/ Ċ fun ĠUi Component Ro . bl urred (): ĠSignal < () Ġ-> ĠUnit > Ġ{ Ċ ĉ return Ġfocus Attachment (). bl urred Ċ } Ċ Ċ /** Ċ Ġ* Ġ@ see ĠFocus Attachment . focused Self Ċ Ġ*/ Ċ fun ĠUi Component Ro . focused Self (): ĠSignal < () Ġ-> ĠUnit > Ġ{ Ċ ĉ return Ġfocus Attachment (). focused Self Ċ } Ċ Ċ /** Ċ Ġ* Ġ@ see ĠFocus Attachment . bl urred Self Ċ Ġ*/ Ċ fun ĠUi Component Ro . bl urred Self (): ĠSignal < () Ġ-> ĠUnit > Ġ{ Ċ ĉ return Ġfocus Attachment (). bl urred Self Ċ }