@@ -151,7 +151,7 @@ impl InputState {
151151
152152 fn mouse_input ( & mut self , button : & MouseButton , state : & ElementState ) -> ClickCount {
153153 self . mouse_state . update ( button, state) ;
154- self . mouse_click_tracker . input ( button, state, & self . mouse_position )
154+ self . mouse_click_tracker . input ( button, state, self . mouse_position )
155155 }
156156
157157 fn cef_modifiers ( & self , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> CefModifiers {
@@ -187,7 +187,7 @@ impl From<&mut InputState> for MouseEvent {
187187 }
188188}
189189
190- #[ derive( Default , Clone ) ]
190+ #[ derive( Default , Clone , Copy ) ]
191191pub ( crate ) struct MousePosition {
192192 x : usize ,
193193 y : usize ,
@@ -233,26 +233,41 @@ struct ClickTracker {
233233 right : Option < ClickRecord > ,
234234}
235235impl ClickTracker {
236- fn input ( & mut self , button : & MouseButton , state : & ElementState , position : & MousePosition ) -> ClickCount {
236+ fn input ( & mut self , button : & MouseButton , state : & ElementState , position : MousePosition ) -> ClickCount {
237237 let record = match button {
238238 MouseButton :: Left => & mut self . left ,
239239 MouseButton :: Right => & mut self . right ,
240240 MouseButton :: Middle => & mut self . middle ,
241241 _ => return ClickCount :: Single ,
242242 } ;
243243
244- let now = Instant :: now ( ) ;
245-
246244 let Some ( record) = record else {
247- * record = Some ( ClickRecord {
248- time : now,
249- position : position. clone ( ) ,
250- down_count : ClickCount :: Single ,
251- up_count : ClickCount :: Single ,
252- } ) ;
245+ * record = Some ( ClickRecord { position, ..Default :: default ( ) } ) ;
253246 return ClickCount :: Single ;
254247 } ;
255248
249+ let now = Instant :: now ( ) ;
250+ record. time = now;
251+ record. position = position;
252+
253+ match state {
254+ ElementState :: Pressed if record. down_count == ClickCount :: Double => {
255+ * record = ClickRecord {
256+ down_count : ClickCount :: Single ,
257+ ..* record
258+ } ;
259+ return ClickCount :: Single ;
260+ }
261+ ElementState :: Released if record. up_count == ClickCount :: Double => {
262+ * record = ClickRecord {
263+ up_count : ClickCount :: Single ,
264+ ..* record
265+ } ;
266+ return ClickCount :: Single ;
267+ }
268+ _ => { }
269+ }
270+
256271 let dx = position. x . abs_diff ( record. position . x ) ;
257272 let dy = position. y . abs_diff ( record. position . y ) ;
258273 let within_dist = dx <= MULTICLICK_ALLOWED_TRAVEL && dy <= MULTICLICK_ALLOWED_TRAVEL ;
@@ -261,33 +276,19 @@ impl ClickTracker {
261276 let count = if within_time && within_dist { ClickCount :: Double } else { ClickCount :: Single } ;
262277
263278 * record = match state {
264- ElementState :: Pressed => ClickRecord {
265- time : now,
266- position : position. clone ( ) ,
267- down_count : count. clone ( ) ,
268- up_count : record. up_count . clone ( ) ,
269- } ,
270- ElementState :: Released => ClickRecord {
271- time : now,
272- position : position. clone ( ) ,
273- down_count : record. down_count . clone ( ) ,
274- up_count : count. clone ( ) ,
275- } ,
279+ ElementState :: Pressed => ClickRecord { down_count : count, ..* record } ,
280+ ElementState :: Released => ClickRecord { up_count : count, ..* record } ,
276281 } ;
277282 count
278283 }
279284}
280285
281- #[ derive( Clone ) ]
286+ #[ derive( Clone , Copy , PartialEq , Default ) ]
282287enum ClickCount {
288+ #[ default]
283289 Single ,
284290 Double ,
285291}
286- impl Default for ClickCount {
287- fn default ( ) -> Self {
288- Self :: Single
289- }
290- }
291292impl From < ClickCount > for i32 {
292293 fn from ( count : ClickCount ) -> i32 {
293294 match count {
@@ -297,13 +298,25 @@ impl From<ClickCount> for i32 {
297298 }
298299}
299300
301+ #[ derive( Clone , Copy ) ]
300302struct ClickRecord {
301303 time : Instant ,
302304 position : MousePosition ,
303305 down_count : ClickCount ,
304306 up_count : ClickCount ,
305307}
306308
309+ impl Default for ClickRecord {
310+ fn default ( ) -> Self {
311+ Self {
312+ time : Instant :: now ( ) ,
313+ position : Default :: default ( ) ,
314+ down_count : Default :: default ( ) ,
315+ up_count : Default :: default ( ) ,
316+ }
317+ }
318+ }
319+
307320struct CefModifiers ( u32 ) ;
308321impl CefModifiers {
309322 fn new ( input_state : & InputState , location : & winit:: keyboard:: KeyLocation , is_repeat : bool ) -> Self {
0 commit comments