]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg/Browser: Share default if some default value are not specified
authorDandan Bi <dandan.bi@intel.com>
Wed, 10 Aug 2016 11:54:21 +0000 (19:54 +0800)
committerStar Zeng <star.zeng@intel.com>
Thu, 11 Aug 2016 07:36:44 +0000 (15:36 +0800)
Add a new implementation policy of getting default value in SetupBrowser.
The new policy is only for the situation that a question has default
value but doesn't have default value for all supported default type.
In this case, we will choose the smallest default id from the existing
defaults, and share its value to other default id which has no
default value.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdeModulePkg/Universal/SetupBrowserDxe/IfrParse.c
MdeModulePkg/Universal/SetupBrowserDxe/Setup.c

index 11a8fdc30daaaeb01afa49dc224051b042a8c6c9..61ba0b50474daaecfe56e26c3e54b33c0fd519e8 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 Parser for IFR binary encoding.\r
 \r
-Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -1311,6 +1311,9 @@ ParseOpCodes (
   INTN                    ConditionalExprCount;\r
   BOOLEAN                 InUnknownScope;\r
   UINT8                   UnknownDepth;\r
+  FORMSET_DEFAULTSTORE    *PreDefaultStore;\r
+  LIST_ENTRY              *DefaultLink;\r
+  BOOLEAN                 HaveInserted;\r
 \r
   SuppressForQuestion      = FALSE;\r
   SuppressForOption        = FALSE;\r
@@ -1875,17 +1878,31 @@ ParseOpCodes (
     // DefaultStore\r
     //\r
     case EFI_IFR_DEFAULTSTORE_OP:\r
+      HaveInserted = FALSE;\r
       DefaultStore = AllocateZeroPool (sizeof (FORMSET_DEFAULTSTORE));\r
       ASSERT (DefaultStore != NULL);\r
       DefaultStore->Signature = FORMSET_DEFAULTSTORE_SIGNATURE;\r
 \r
       CopyMem (&DefaultStore->DefaultId,   &((EFI_IFR_DEFAULTSTORE *) OpCodeData)->DefaultId,   sizeof (UINT16));\r
       CopyMem (&DefaultStore->DefaultName, &((EFI_IFR_DEFAULTSTORE *) OpCodeData)->DefaultName, sizeof (EFI_STRING_ID));\r
-\r
       //\r
-      // Insert to DefaultStore list of this Formset\r
+      // Insert it to the DefaultStore list of this Formset with ascending order.\r
       //\r
-      InsertTailList (&FormSet->DefaultStoreListHead, &DefaultStore->Link);\r
+      if (!IsListEmpty (&FormSet->DefaultStoreListHead)) {\r
+        DefaultLink = GetFirstNode (&FormSet->DefaultStoreListHead);\r
+        while (!IsNull (&FormSet->DefaultStoreListHead, DefaultLink)) {\r
+          PreDefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink);\r
+          DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead, DefaultLink);\r
+          if (DefaultStore->DefaultId < PreDefaultStore->DefaultId) {\r
+            InsertTailList (&PreDefaultStore->Link, &DefaultStore->Link);\r
+            HaveInserted = TRUE;\r
+            break;\r
+          }\r
+        }\r
+      }\r
+      if (!HaveInserted) {\r
+        InsertTailList (&FormSet->DefaultStoreListHead, &DefaultStore->Link);\r
+      }\r
       break;\r
 \r
     //\r
index 6b38547c5e7988a8018cb40e7bd5eb0f161ef180..66c43138612e7c981a632748adc18657ad7760a7 100644 (file)
@@ -4050,9 +4050,14 @@ GetQuestionDefault (
   INTN                            Action;\r
   CHAR16                          *NewString;\r
   EFI_IFR_TYPE_VALUE              *TypeValue;\r
+  UINT16                          OriginalDefaultId;\r
+  FORMSET_DEFAULTSTORE            *DefaultStore;\r
+  LIST_ENTRY                      *DefaultLink;\r
 \r
   Status   = EFI_NOT_FOUND;\r
   StrValue = NULL;\r
+  OriginalDefaultId  = DefaultId;\r
+  DefaultLink        = GetFirstNode (&FormSet->DefaultStoreListHead);\r
 \r
   //\r
   // Statement don't have storage, skip them\r
@@ -4069,6 +4074,7 @@ GetQuestionDefault (
   //  4, set flags of EFI_ONE_OF_OPTION (provide Standard and Manufacturing default)\r
   //  5, set flags of EFI_IFR_CHECKBOX (provide Standard and Manufacturing default) (lowest priority)\r
   //\r
+ReGetDefault:\r
   HiiValue = &Question->HiiValue;\r
   TypeValue = &HiiValue->Value;\r
   if (HiiValue->Type == EFI_IFR_TYPE_BUFFER) {\r
@@ -4235,7 +4241,22 @@ GetQuestionDefault (
   }\r
 \r
   //\r
-  // For Questions without default\r
+  // For question without default value for current default Id, we try to re-get the default value form other default id in the DefaultStoreList.\r
+  // If get, will exit the function, if not, will choose next default id in the DefaultStoreList.\r
+  // The default id in DefaultStoreList are in ascending order to make sure choose the smallest default id every time.\r
+  //\r
+  while (!IsNull(&FormSet->DefaultStoreListHead, DefaultLink)) {\r
+    DefaultStore = FORMSET_DEFAULTSTORE_FROM_LINK(DefaultLink);\r
+    DefaultLink = GetNextNode (&FormSet->DefaultStoreListHead,DefaultLink);\r
+    DefaultId = DefaultStore->DefaultId;\r
+    if (DefaultId == OriginalDefaultId) {\r
+      continue;\r
+    }\r
+    goto ReGetDefault;\r
+  }\r
+\r
+  //\r
+  // For Questions without default value for all the default id in the DefaultStoreList.\r
   //\r
   Status = EFI_NOT_FOUND;\r
   switch (Question->Operand) {\r