[ggl-user] Incorrect scrolling adjustment when selecting items in Listbox element using mouse

6 views
Skip to first unread message

Cecil Wei

unread,
May 23, 2010, 11:21:09 PM5/23/10
to google-gadgets-for-linux-user
hello,

There is one issue I found in listbox element and I am not sure if it
is a problem or not.

When there are many items in the listbox and scrollbar is displayed,
you click on one item with mouse and you will see the scrollbar moves
to the top.

I checked the behavior in Window version and it doesn't exhibit the
same behavior.

I then checked the implementation of
ListBoxElement::Impl::SetSelectedItem

void SetSelectedItem(ItemElement *item) {
bool changed = ClearSelection(item);
if (item && !item->IsSelected()) {
item->SetSelected(true);
pending_scroll_ = 2;
changed = true;
}

if (changed)
FireOnChangeEvent();
}

The selected_index_ is not set and therefore when Layout is called the
scrolling position is changed incorrectly.

I then tried by adding

selected_index_ = item->GetIndex(); and it works fine

can you kindly confirm if this is an issue or not? thank you,

--
You received this message because you are subscribed to the Google Groups "google-gadgets-for-linux-user" group.
To post to this group, send email to google-gadgets...@googlegroups.com.
To unsubscribe from this group, send email to google-gadgets-for-l...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gadgets-for-linux-user?hl=en.

James Su

unread,
May 23, 2010, 11:55:09 PM5/23/10
to google-gadgets...@googlegroups.com


2010/5/23 Cecil Wei <ceci...@gmail.com>

hello,

There is one issue I found in listbox element and I am not sure if it
is a problem or not.

When there are many items in the listbox and scrollbar is displayed,
you click on one item with mouse and you will see the scrollbar moves
to the top.

I checked the behavior in Window version and it doesn't exhibit the
same behavior.

I then checked the implementation of
ListBoxElement::Impl::SetSelectedItem

 void SetSelectedItem(ItemElement *item) {
   bool changed = ClearSelection(item);
   if (item && !item->IsSelected()) {
     item->SetSelected(true);
     pending_scroll_ = 2;
     changed = true;
   }

   if (changed)
     FireOnChangeEvent();
 }

The selected_index_ is not set and therefore when Layout is called the
scrolling position is changed incorrectly.

I then tried by adding

selected_index_ = item->GetIndex(); and it works fine
According to the code, SetSelectedItem() should not set selected_index_, which is only used for setting selected item in XML. Do you have a demo gadget the can reproduce this issue?
 

can you kindly confirm if this is an issue or not? thank you,

--
You received this message because you are subscribed to the Google Groups "google-gadgets-for-linux-user" group.
To post to this group, send email to google-gadgets...@googlegroups.com.
To unsubscribe from this group, send email to google-gadgets-for-l...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-gadgets-for-linux-user?hl=en.

Message has been deleted

Cecil Wei

unread,
May 24, 2010, 1:44:16 AM5/24/10
to google-gadgets-for-linux-user
Hi James,

The script having problem is as follows:

function _searchHotWord() {
var lb = listbox_div.children.item("listbox");
if(lb != null) {
var selItem = lb.selectedItem;
var label = selItem.children.item("lab_"+selItem.name);
if(label.innerText != "") {
d_keyword.value = hotwordArr[selItem.name];
}
lb.clearSelection();
}

}

I think the problem is the selection is cleared before Layout is
reperformed.

So my patch may not be correct. However the content is not scrolled in
windows version.

Any idea?

thanks,

Xianzhu Wang

unread,
May 24, 2010, 1:57:18 AM5/24/10
to google-gadgets...@googlegroups.com
For now ListBoxElement depend on which item is selected to determine how to scroll the list. We can add pending_scroll_ = 0 in ClearSelection() to avoid unexpected scroll in your case (that is, ClearSelection() is called after SetSelectedItem() in the same event loop).

As a workaround, you can delay ClearSelection() to the next event loop:
    setTimeout(function() { lb.clearSelection(); }, 0);

About selected_index_, it is designed to record the value of selectedIndex attribute in XML, and will be no more used after the first layout. Maybe we should name it xml_selected_index_ instead to avoid confusion.

2010/5/24 Cecil Wei <ceci...@gmail.com>

Xianzhu Wang

unread,
May 24, 2010, 4:45:18 AM5/24/10
to google-gadgets...@googlegroups.com
Hi, Cecil,

The issue has been fixed in the trunk. Thanks for reporting and analyzing!

Xianzhu

2010/5/24 Xianzhu Wang <phni...@gmail.com>
Reply all
Reply to author
Forward
0 new messages